- #1

dRic2

Gold Member

- 813

- 198

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

but It gives wrong results.

Thanks

Ric

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_y
global 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
```

Thanks

Ric

Last edited: