Get x and y coordinates of motion from ode45

14 views (last 30 days)
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
  1 Comment
Torsten
Torsten on 30 Nov 2018
How does your equation from above look if you write it out ?
Is it
d^2(r_x)/dt^2 = 0
d^2(r_y)/dt^2 = -g*M*r_y/r0^3
with initial conditions
r_x(0) = r0, d(r_x)(0)/dt = 0, r_y(0) = 0, d(r_y)(0)/dt = v0
?

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 30 Nov 2018
Edited: James Tursa on 30 Nov 2018
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)
  10 Comments
James Tursa
James Tursa on 2 Dec 2018
Edited: James Tursa on 2 Dec 2018
It's likely spiraling down because of ode45 integration errors. I.e., the ode45 method isn't particularly well suited for this problem. Try tightening the tolerances (see the options structure argument).
Backtobasics
Backtobasics on 2 Dec 2018
Edited: Backtobasics on 2 Dec 2018
Amazing, it worked perfectly! Thank you so, so much!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!