multiple graphs for two or more functions for different values in different color
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
n=2; y1=0.5 (q.^2*n-5*q.^n+(2*q-1).^(n+3)) y2=0.5(q.^2*n-7*q.^n+2*(2*q-1).^(n+4))
i want to plot the graphs(in one figure) of above two or more functions for the different values of q>=2 for example these values can be q=2,3,,4,5
Accepted Answer
madhan ravi
on 30 Oct 2018
Edited: madhan ravi
on 1 Nov 2018
n=2;
q=2:5
y1=0.5.*(q.^2.*n-5.*q.^n+(2.*q-1).^(n+3))
y2=0.5.*(q.^2.*n-7.*q.^n+2.*(2.*q-1).^(n+4))
y3=(1/12).*(4.*q.^n-1-9*q.^n + 3.*(2.*q-1).^(n+9))
y4=2.*(q.^n-2).*(q.^2*n-3.*q.^n+(2*q-1).^n + 1)
y5=0.5.*(q.^2.*n-4.*q.^n-(2.*q-1).^n+3)
subplot(5,1,1)
plot(q,y1,'-r','LineWidth', 2)
subplot(5,1,2)
plot(q,y2,'-b','LineWidth', 2)
subplot(5,1,3)
plot(q,y3,'-k','LineWidth', 2)
subplot(5,1,4)
plot(q,y4,'-y','LineWidth', 2)
subplot(5,1,5)
plot(q,y5,'-g','LineWidth', 2)
10 Comments
Shahid Rafiq
on 30 Oct 2018
thanks dear but when i have five functions like this y1,y2,y3,y4,y5 the hold on command is not working i receive just two graphs
madhan ravi
on 30 Oct 2018
Edited: madhan ravi
on 30 Oct 2018
It should work , otherwise you are not using it properly
Shahid Rafiq
on 30 Oct 2018
no i just getting two graphs if i select one by one, i receive each graph but multiple graphs are not obtained in a single finger
madhan ravi
on 30 Oct 2018
Upload the code you are trying here
Shahid Rafiq
on 1 Nov 2018
Edited: Shahid Rafiq
on 1 Nov 2018
close all;
clear all;
format longEng
n=2;
q=2:5
y1=0.5*(q.^2.*n-5.*q.^n+(2.*q-1).^(n+3))
y2=0.5*(q.^2.*n-7.*q.^n+2*(2.*q-1).^(n+4))
y3=(1/12)*(4*q.^n-1-9*q.^n + 3*(2*q-1).^(n+9))
y4=2*(q.^n-2)*(q.^2*n-3*q.^n+(2*q-1).^n + 1)
y5=0.5*(q.^2*n-4*q.^n-(2*q-1).^n+3)
plot(q,y1,'-r','LineWidth', 2)
hold on
plot(q,y2,'-b','LineWidth', 2)
plot(q,y3,'-k','LineWidth', 2)
plot(q,y4,'-y','LineWidth', 2)
plot(q,y5,'-g','LineWidth', 2)
hold off
madhan ravi
on 1 Nov 2018
See the edited answer by the way you were not able to see because the plots overlapped oeach other
Shahid Rafiq
on 1 Nov 2018
dear but my requirement still not solved.
these graphs are separate but i want these 5 graphs in a single figure indicating each color description
madhan ravi
on 1 Nov 2018
If you see them carefully they lie on each other so how can you distinguish them?
Shahid Rafiq
on 1 Nov 2018
ok. thanks. what about their caption and legend
madhan ravi
on 1 Nov 2018
xlabel('x') Same for y
legend('1','2','3','4','5')
More Answers (0)
Categories
Find more on Line Plots in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)