how to plot two graphs combined

3 vues (au cours des 30 derniers jours)
Josie
Josie le 20 Août 2014
Commenté : Ben11 le 21 Août 2014
I need to plot P=0.5+thetax on 0<x<0.33 and then P=theta(x-1) on 0.33<x<1. Do i use a for loop to do this? And if so how? Here is my code so far
x=linspace(0,1,50);
g=10;
A=0.33
M=0.125
s=(A-0.5)*M.*g-(A^2)/4;
theta=s./(2*M.*(A-0.5)^2+2*M+(A^2-A+1/3)/2);
P=(1/2)+theta*(x-1);
plot(x,P)
axis([0,1,-2,2])

Réponse acceptée

Ben11
Ben11 le 20 Août 2014
Modifié(e) : Ben11 le 20 Août 2014
Maybe something like this:
x=linspace(0,1,50)
g=10;
A=0.33
M=0.125
s=(A-0.5)*M.*g-(A^2)/4;
theta=s./(2*M.*(A-0.5)^2+2*M+(A^2-A+1/3)/2);
P=(1/2)+theta*(x-1);
xS = x< 0.33 % define x < 0.33
xL = x>0.33 % define x > 0.33
figure
plot(x(xS),0.5+theta*x(xS))
hold on
plot(x(xL),theta*(x(xL)-1))
hold off
axis([0,1,-2,2])
  4 commentaires
Josie
Josie le 21 Août 2014
Great! Thank you
Ben11
Ben11 le 21 Août 2014
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by