Plotting the Orbit of planets with MATLAB

Click For Summary

Discussion Overview

The discussion revolves around plotting the orbits of planets using MATLAB, specifically focusing on the polar equations that model these orbits. Participants share their approaches to solving a homework problem related to this topic, including coding techniques and plotting methods.

Discussion Character

  • Homework-related
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant presents a homework problem involving the polar equation for planetary orbits and requests guidance on how to start.
  • Another participant suggests evaluating expressions for a range of theta values and using the polar function in MATLAB for plotting.
  • A participant shares a code snippet that successfully plots a single planet's orbit, expressing gratitude for the assistance received.
  • Further, a participant shares their completed script and asks for suggestions on improving it, including adding titles to plots, creating a polar paper for the combined plot, and animating the orbits.

Areas of Agreement / Disagreement

Participants generally agree on the approach to plotting orbits using MATLAB, but there are multiple suggestions regarding improvements and features to be added to the script, indicating a lack of consensus on the best methods for implementation.

Contextual Notes

Some limitations are noted, such as the absence of titles in individual planet plots and the desire for animation features, which remain unresolved in the discussion.

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 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K