MATLAB Plotting the Orbit of planets with MATLAB

AI Thread Summary
The discussion focuses on plotting the orbits of four planets using MATLAB, specifically utilizing a polar equation to model their paths around the sun. Users are guided on how to implement the polar plot function and evaluate the expressions for varying values of the constants P and e for each planet. The conversation includes troubleshooting and code suggestions for improving the plot, such as adding titles and creating a combined plot for all planets. Additionally, there are inquiries about animating the orbits to depict motion. The thread concludes with users sharing their completed scripts and seeking further enhancements.
cannibal
Messages
14
Reaction score
0

Homework Statement



Hi everyone, i was presented with this problem in my Computer Programming for Engineers Class.

The orbit of the planets around the sun can approximately be
modeled by the polar equation:

[URL]http://www.prml.org/images/71715equation.PNG[/URL]The values of the constants P and e for four planets are given
below. Plot the orbits of the four planets in one figure (use the hold
on command).

Planet----|----P (x^10^6 m)----|e------------Planet----|----P(x^10^6 m)----|e
Mercury-------269.2-------------0.206---------Earth---------8964-------------0.0167
Venus---------15913-------------0.00677-------Mars---------2421-------------0.0934

Homework Equations



[URL]http://www.prml.org/images/71715equation.PNG[/URL]

The Attempt at a Solution

Can anyone approach me to how i can begin this problem ? i have no idea of even how to begin it :confused:
 
Last edited by a moderator:
Physics news on Phys.org
Just evaluate the expressions for a range of theta for each value of P and e.

polar(theta,R) makes polar plots in Matlab.

Have you ever used Matlab before?
 
LeBrad said:
Just evaluate the expressions for a range of theta for each value of P and e.

polar(theta,R) makes polar plots in Matlab.

Have you ever used Matlab before?

Well i have used it but, i was not introduced to plotting :frown:
 
vedenev said:
Code:
t=0:pi/40:2*pi;
P=200;
e=0.2;
R=e*P./(1-e*cos(t));
polar(t,R);
--------------------
Maxim Vedenev, Matlab freelancer, vedenev@ngs.ru
http://simulations.narod.ru/matlab/


:approve: Thank you very much vedenev that worked :D and thanks to LeBrad too. When i finish the exercise I will post it here.
 
Okay :D i just finished i came up with this script, any suggestions ?, once again thanks to vedenew and LeBrad.

Problems:

1. Single planets orbits are plotting without Title.
2. I would like the "All planets" plot to be in a Polar Paper
3. Anyway i can make the orbits move ? i mean like do a circular motion ?


Thanks

Code:
%Global Variables Begin
op=0; clc
z=0:pi/40:2*pi;
%Global Variables Ends

%User Menu Begins
while op~=6 
disp ('Planet Orbit Plotter')
disp('1)Mercury')
disp('2)Venus')
disp('3)Earth')
disp('4)Mars')
disp('5)All')
disp('6)Exit')
op = input ('Please choose an option: ');
%User Menu Ends

switch op
    case 1 %Mercury's Orbit
        
        TITLE('Mercury''s Orbit')
        P=269.2;
        e=.206;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'m . -');
        pause
        
    case 2 %Venus Orbit
        
        TITLE('Venus Orbit')
        hold on
        P=15913;
        e=.00677;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'c . -');
        pause
        
    case 3 %Earth's Orbit
        
        TITLE('Earth''s Orbit')
        hold
        P=8964;
        e=.0167;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'b . -');
        pause
        
    case 4 %Mars Orbit
        
        title ('Mars Orbit')
        hold on
        P=2421;
        e=.0934;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'R . -');
        pause
        
    case 5 % All four orbits
        
        TITLE('Mercury, Venus, Earth and Mars Orbits')
        
        hold all
        %Mercury Orbit
        P=269.2;
        e=.206;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'m . -'); grid on
        
        %Venus Orbit
        P=15913;
        e=.00677;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'c . -'); grid on
        
        %Earth's Orbit
        P=8964;
        e=.0167;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'b . -'); grid on
        
        %Mars Orbit
        P=2421;
        e=.0934;
        R=(e*P)./(1-e*cos(z));
        polar(z,R,'R . -'); grid on
        
        legend('First','Second','Third','Fourth');
        legend('Mercury','Venus','Earth','Mars','Location','EastOutside')
        
    otherwise
        break
end
clc
end
 

Similar threads

Replies
2
Views
3K
Replies
1
Views
8K
Replies
2
Views
3K
Replies
9
Views
5K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
4
Views
3K
Replies
7
Views
3K
Back
Top