1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Modeling Motion of Earth with Matlab using ODE45

  1. Dec 12, 2015 #1
    1. The problem statement, all variables and given/known data
    So I am trying to model the motion of the Earth around the Sun using ode45. I modeled this using an euler-cromer scheme, but I would like to get familiar with using a solver. I wrote the code for an Euler-cromer and it worked just fine. However, when I try to use the same equation that I derived for acceleration in the Euler scheme in the ODE, I get errors. I think it is because I am not quite sure how the inputs work for ODE. I have tried to figure it out by looking through resources on the internet, but I just can't figure it out.

    2. Relevant equations
    The equation I used was the vector form of acceleration of a mass due to another mass. This equation in matlab is

    -G * Msun * R / (sum(R.*R)^(3/2)) where R = Psun - Current position (as vectors, [x y] - [x y]).

    3. The attempt at a solution

    This is my attempt, which provides this error:

    In an assignment A(:) = B, the number of elements in A and B
    must be the same.

    Error in orbit (line 10)
    dp(2) = -G * Msun * R / (sum(R.*R)^(3/2));

    My function:
    G = 6.673E-11/(1000^3);

    Psun = [0 0];

    Msun=1.988e30;

    R = Psun - P(2);

    M = 1.98892E30;

    dp = zeros(2,2);

    dp(1)= P(2);

    dp(2) = -G * Msun * R / (sum(R.*R)^(3/2));

    How I call it:

    [T,Y] = ode45(@Orbit,[0, 3.15581e7],[1.5e8, 0, 0, 29.75]);
     
  2. jcsd
  3. Dec 13, 2015 #2

    DrClaude

    User Avatar

    Staff: Mentor

    The problem you have has for degrees of freedom: ##x, y, \dot{x}, \dot{y}##. Your function is set up with only 2. It need to be able to take in a vector y of length 4, containing the 4 dof, and return a vector y' of length 4 also.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Modeling Motion of Earth with Matlab using ODE45
  1. Matlab: ode45 help (Replies: 1)

  2. Matlab ode45 Problem (Replies: 5)

Loading...