So i have the equations of
%Vehicle 1 V1f = (M1*V1 + M2*V2 + M2*E*(V2-0)) / (M1 +M2);
%Vehicle 2 V2f = (M1*V1 + M2*V2 + M1*E*(V1-V2)) / (M1 +M2);
%Time Traveled
T1=(M1*V1f) / (U*M1*G);
T2= (M2*V2f) / (U*M2*G);
%Distance traveled after the Collision
%Vehicle 1
s1 = (V1f*T1) -(.5*U*G*T1^2);
%Vehicle 2
s2 = (V2f*T2) -(.5*U*G*T2^2);;
I need to have a line graph comparing S1 vs T1 and S2 vs T2. How would i create a line graph of these.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Ag. de 2011

0 votos

plot(T1, s1, 'r', T2, s2, 'g')
This presumes that T1 and T2 are each vectors of times after their calculation. But if so, if they are vectors, then you probably need to change your s equations slightly:
%Distance traveled after the Collision
%Vehicle 1
s1 = (V1f.*T1) -(.5*U*G*T1.^2);
%Vehicle 2
s2 = (V2f.*T2) -(.5*U*G*T2.^2);

5 comentarios

Kyle Taliaferro
Kyle Taliaferro el 31 de Ag. de 2011
Lets say after i run the program i wrote that i get T1= .256 and s1 = .3285. How could do a graph with s1 as a function of time. Where it will show me from s1=0 to s1=.3285 with respect to a certain time
Walter Roberson
Walter Roberson el 31 de Ag. de 2011
Are you asking for an interpolation of some kind, such as a prediction of what time s1 would have reached (e.g.) 0.2345 based upon the ouputs that had s1 = 0.3285 when T1 = 0.256 ?
If so, then presuming that U and G are positive and presuming that you want non-negative times,
Tn = (V1f+(V1f^2-2*U*G*s1n)^(1/2))/U/G
would be the time Tn at which the s value s1n would be reached.
NumPoints = 1000;
s1n = linspace(0,s1,NumPoints);
T1n = (V1f+sqrt(V1f^2-2*U*G*s1n))/(U*G);
plot(T1n, s1n,'b')
Kyle Taliaferro
Kyle Taliaferro el 31 de Ag. de 2011
i dont want interpolation. I want a graph that will have the x axis going from 0 to .256 and then have point inbetween 0 and .256
get plugged into the s1 equation.
t1n=linspace(0,T1,200)
have each t1n point get plugged into s1 and the plot the two
Walter Roberson
Walter Roberson el 31 de Ag. de 2011
Like,
t1n = linspace(0,T1,200);
s1n = (V1f.*t1n) -(.5*U*G*t1n.^2);
plot(t1n, s1n)
Kyle Taliaferro
Kyle Taliaferro el 31 de Ag. de 2011
Yes. Thankyou. That did the trick.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Networks en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by