Modeling Motion of Earth with Matlab using ODE45

Click For Summary
SUMMARY

The discussion focuses on modeling the motion of the Earth around the Sun using MATLAB's ODE45 solver. The user initially implemented an Euler-Cromer scheme but encountered errors when transitioning to ODE45 due to incorrect handling of input dimensions and vector outputs. The key equation used for acceleration is -G * Msun * R / (sum(R.*R)^(3/2)), where R represents the vector difference between the Sun's position and the current position. The user must adjust their function to accommodate a state vector of length four, representing the position and velocity components.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with numerical methods, specifically ODE solvers
  • Knowledge of vector calculus and gravitational equations
  • Basic concepts of celestial mechanics and orbital dynamics
NEXT STEPS
  • Review MATLAB's ODE45 documentation for proper input and output handling
  • Learn about state-space representation in dynamical systems
  • Explore vector operations in MATLAB to manipulate position and velocity vectors
  • Investigate common errors in MATLAB related to matrix dimensions and assignments
USEFUL FOR

Students and researchers in physics or engineering, particularly those interested in computational modeling of celestial mechanics and numerical simulations using MATLAB.

PhysSci1
Messages
1
Reaction score
0

Homework Statement


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.

Homework 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]).

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]);
 
Physics news on Phys.org
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
Replies
5
Views
6K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K