How to plot multiple functions on one graph>
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
James Tursa
2015년 4월 17일
편집: James Tursa
2015년 4월 17일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!