MATLAB: Get x and y coordinates of motion from ode45

MATLABode45orbitvector in ode45

Hi,
I would like to plot the motion of a satellite in the x-y-plane around the Earth. For this motion I have the differential equation
. As initial conditions, I have and with two numerical values for r and v and I want to pass them to ode45 via
[t1, y1]=ode45('unperturbed', [0 100], [r0 v0]);
How does unperturbed have to look like so it can handle the vectors and returns a position vector for every time t?
So far I have it like this which seems to return valid y coordinates but I don't know how to get the x part.
function dy = unperturbed(t,y)
M=5.594e24;
G=6.674e-11;
rE=6378.137;
r0=rE+800;
dy=zeros(2,1);
dy(1) = y(2);
dy(2) = -G*M*(dy(1)/r0^3);
end
I hope you can help me with this

Best Answer

You've got a 4th order system (2 equations for x and y, each 2nd order --> 2 x 2 = 4), so your state vector will need to be 4 elements, not 2 elements like you currently have. Define the state vector as follows and then work from there:
y(1) = the x position
y(2) = the y position
y(3) = the x velocity
y(4) = the y velocity
Then in your derivative function you will have something like this:
dy=zeros(4,1); % 4th order system so 4 elements
dy(1) = y(3);
dy(2) = y(4);
% the -GM *rvec/r^3 calculation goes here (this will be a vector result)
dy(3) = _____; % you fill this in, based on the vector result above

dy(4) = _____; % you fill this in, based on the vector result above
Side Note: The DEQ in your Question is missing a minus sign (even though you do have it in your code)
Related Question