Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plotting the Orbit of planets with MATLAB

  1. Feb 9, 2008 #1
    1. The problem statement, all variables and given/known data

    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:

    [​IMG]


    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


    2. Relevant equations

    [​IMG]

    3. 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: Feb 10, 2008
  2. jcsd
  3. Feb 10, 2008 #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?
     
  4. Feb 10, 2008 #3
    Well i have used it but, i was not introduced to plotting :frown:
     
  5. Feb 10, 2008 #4

    :approve: Thank you very much vedenev that worked :D and thanks to LeBrad too. When i finish the exercise I will post it here.
     
  6. Feb 10, 2008 #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 (Text):

    %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  




     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Plotting the Orbit of planets with MATLAB
  1. MATLAB plots (Replies: 1)

  2. Matlab Plot (Replies: 2)

  3. Plotting in MATLAB (Replies: 8)

  4. Plotting with MATLAB (Replies: 1)

Loading...