Plotting the Orbit of planets with MATLAB

In summary, the conversation is about a problem presented in a Computer Programming for Engineers class involving plotting the orbits of four planets using a polar equation. The conversation includes suggestions on how to approach the problem, such as evaluating expressions for a range of theta and using polar plots in Matlab. The individual asking for help also shares their own solution to the problem, which includes code for plotting each planet's orbit and a menu option for plotting all four orbits at once.
  • #1
cannibal
14
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
  • #2
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?
 
  • #3
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:
 
  • #4
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.
 
  • #5
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
 

1. How do I use MATLAB to plot the orbit of a planet?

To plot the orbit of a planet using MATLAB, you will need to first gather data on the planet's position and velocity at different points in time. This data can be obtained from reliable sources such as NASA's Jet Propulsion Laboratory. Once you have the necessary data, you can use MATLAB's built-in functions such as "plot" and "scatter" to create a visual representation of the planet's orbit.

2. Can I plot the orbit of multiple planets using MATLAB?

Yes, you can plot the orbits of multiple planets using MATLAB. You will need to gather data for each planet and then use MATLAB's "hold" function to plot the orbits on the same figure. This will allow you to compare and analyze the orbits of different planets.

3. What factors affect the shape of a planet's orbit?

The shape of a planet's orbit is primarily determined by its distance from the sun and its velocity. These two factors, along with the mass of the planet and any external forces, affect the planet's orbit and can result in a circular, elliptical, or parabolic shape.

4. Can MATLAB be used to predict the future path of a planet's orbit?

Yes, MATLAB can be used to predict the future path of a planet's orbit. By using the planet's current position and velocity, along with its known orbital parameters, you can create a mathematical model in MATLAB that can accurately predict the planet's future path. However, external factors such as gravitational influences from other celestial bodies may cause slight deviations from the predicted path.

5. Are there any limitations to using MATLAB to plot the orbit of planets?

There are a few limitations to using MATLAB to plot the orbit of planets. One limitation is that it assumes a two-dimensional plane for the orbit, which may not be accurate for certain planets. Additionally, MATLAB does not take into account all external factors that can affect a planet's orbit, so the plotted orbit may not be 100% accurate. It is always important to validate the results with other sources of data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Replies
17
Views
2K
  • Astronomy and Astrophysics
Replies
10
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Introductory Physics Homework Help
Replies
1
Views
825
Back
Top