System of differential equations

In summary, the problem was solved by rewriting it in terms of vectors and using an appropriate ode solver.
  • #1
dRic2
Gold Member
883
225
Hi, I was trying to solve the simplest problem of planetary motion (for one planet).

The equations should be:

##F_x = m \frac {d^2x} {dt^2} = G \frac {Mmx} {r^3}##
##F_y = m \frac {d^2y} {dt^2} = G \frac {Mmy} {r^3}##

where ## r = \sqrt{x^2 + y^2}##

So I re-wrote the system like this:

##\frac {dx} {dt} = v_x##
##\frac {dy} {dt} = v_y##
##\frac {dv_x} {dt} = G \frac {Mmx} {r^3}##
##\frac {dv_y} {dt} = G \frac {Mmy} {r^3}##

I'm not sure how to implement this in matlab...

I tried this

Code:
function out = sis(t, s)

% s(1) is x
% s(2) is y
% s(3) is v_x
% s(4) is v_yglobal G Ms Mt
out = zeros(4,1);out(1) = s(3);

out(2) = s(4);r = sqrt(s(1)^2 + s(2)^2);out(3) = G * Ms * Mt * s(1) / (r^3);

out(4) = G * Ms * Mt * s(2) / (r^3);end

but It gives wrong results.

Thanks
Ric
 
Last edited:
Physics news on Phys.org
  • #2
Why do you set out(1) = s(3) and out(2) = s(4) shouldn't they be something like out(1) = s(1) + t*s(3) and out(2) = s(2) + t*s(4) ?

and is the v_z really v_y?
 
  • #3
jedishrfu said:
and is the v_z really v_y?
yes, my bad.

jedishrfu said:
Why do you set out(1) = s(3) and out(2) = s(4) shouldn't they be something like out(1) = s(1) + t*s(3) and out(2) = s(2) + t*s(4) ?

I want to use ode45 instead of manually implement the algorithm and I though that is the way to do it.
 
  • #4
You misunderstood what I was asking. My understanding is that the s array is the state of the system and since s1 and s2 represent the position then you must update the position each time with a delta x and a delta y value.

The delta x is in fact ##vx * \Delta t## which in your case is t giving the ##out1=s1+vx*t## expression.

Do you see what I mean?
 
  • #6
  • Like
Likes dRic2
  • #7
dRic2 said:
but It gives wrong results.
You'll have to elaborate.
 
  • #8
Thanks @jedishrfu, very nice link!

First of all, I forgot the minus sign in front of $\frac GMmx/r^3$. And then, as concerned as I was with mathematics, I totally forgot about the physics of the problem! My initial conditions were wrong and physically inconsistent so the numerical integration kept failing.
 
  • #9
Try ode113 instead of ode45, as it is a variable order solver that includes the results of several past time steps. It is better than ode45 for problems where high precision is required, such as orbital dynamics problems.

Example here:
https://www.mathworks.com/help/matlab/ref/ode113.html#bu6t62o-1_1

ode45 actually outputs more points than it computes - it uses interpolation to get a few extra points per time step, which results in nicer looking plots. That can be adjusted with the 'Refine' option.
 
  • Like
Likes AVBs2Systems and dRic2
  • #10
Thanks @Krell. I was just experimenting with Matlab to get used to it, but it is very useful to know!
 

1. What is a system of differential equations?

A system of differential equations is a set of equations that represent the relationships between multiple variables and their rates of change over time. These equations are used to model dynamic systems in various fields of science and engineering.

2. What are the key components of a system of differential equations?

The key components of a system of differential equations include the dependent variables, independent variables, and the differential equations themselves. The dependent variables are the quantities that are changing over time, while the independent variables are the factors that affect the rate of change. The differential equations describe the relationships between these variables.

3. How is a system of differential equations solved?

There is no one specific method for solving a system of differential equations, as it depends on the specific equations and problem at hand. However, some common techniques include separation of variables, substitution, and using numerical methods such as Euler's method or Runge-Kutta methods.

4. What are some applications of systems of differential equations?

Systems of differential equations are used in various fields of science and engineering, including physics, chemistry, biology, economics, and engineering. They are particularly useful for modeling complex systems that involve multiple variables and their interactions, such as population dynamics, chemical reactions, and mechanical systems.

5. What are the limitations of systems of differential equations?

While systems of differential equations are powerful tools for modeling real-world systems, they also have some limitations. These include the assumption of continuous and differentiable functions, the difficulty of solving complex and nonlinear equations, and the need for accurate initial conditions and parameters. Additionally, the models may not always accurately reflect the behavior of the actual system due to simplifications and assumptions made in the modeling process.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
980
  • Introductory Physics Homework Help
Replies
7
Views
203
  • Introductory Physics Homework Help
2
Replies
63
Views
2K
  • Special and General Relativity
Replies
4
Views
256
Back
Top