multiple graphs for two or more functions for different values in different color

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

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

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
It should work , otherwise you are not using it properly
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
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
See the edited answer by the way you were not able to see because the plots overlapped oeach other
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
If you see them carefully they lie on each other so how can you distinguish them?
ok. thanks. what about their caption and legend
xlabel('x') Same for y
legend('1','2','3','4','5')

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!