How to plot multiple functions on one graph>

4 visualizaciones (últimos 30 días)
DaHart
DaHart el 17 de Abr. de 2015
Comentada: DaHart el 17 de Abr. de 2015
I need to plot the orbits of four different planets on the same graph in Matlab. The code below works for each plot individually, creating the orbit plot that I want. However, when I put all the codes together like I do below, I get a plot that looks like 4 straight lines going in random directions.
ro=[0,0,1.50e11];
vo=[0,2*pi*ro(3)/(365*24*60*60),0];
for n=1:730
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'go')
hold on
ro=r
vo=v
end
ro=[0,0,2.28e11];
vo=[2*pi*ro(2)/(365*24*60*60*1.88),0,0];
for n=0:1:730*1.88
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'ro')
hold on
ro=r
vo=v
end
ro=[0,0.58e11,0];
vo=[2*pi*ro(1)/(365*24*60*60*0.241),0,0];
for n=1:730*.241
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'bo')
hold on
ro=r
vo=v
end
ro=[0,1.08e11,0];
vo=[0,0,2*pi*ro(3)/(365*24*60*60*0.615)];
for n=1:730*.615
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'mo')
hold on
ro=r
vo=v
end
How can I make it so each orbit appears on the graph without affecting the other graphs?
Thanks

Respuesta aceptada

James Tursa
James Tursa el 17 de Abr. de 2015
Editada: James Tursa el 17 de Abr. de 2015
plot3 with hold on should have worked. That being said, looks like the last three cases have vo typos to me, since vo is all 0's in these cases. E.g., the 2nd case has
ro=[0,0,2.28e11];
vo=[2*pi*ro(2)/(365*24*60*60*1.88),0,0];
but ro(2) is 0, so vo(1) will be 0. Did you mean to use ro(3) in this case?
Same comment for all of the last three cases. As you have it, these cases are degenerate rectilinear orbits (i.e., straight lines) falling straight into the planet.
  1 comentario
DaHart
DaHart el 17 de Abr. de 2015
whoops, didn't notice that when I changed the placement of those values. This worked, thanks so much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Earth and Planetary Science en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by