- #1
CaptainEvil
- 99
- 0
I've written a program to show the trajectory of a rocket around the Earth with initial conditions that can be manipulated to fix a circular or elliptical orbit.
We start with Newton's 2nd law and use the equation a=F/m in freespace (so m can divide out) to get a 2nd order ODE and solve by separating them into systems of first order ODEs.
Here's my code for this program:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function xprime = rocketODE(t,x)
%creating a function called roketODE that will solve for a system of first order ODEs of a rocket's motion around the Earth (at the origin)
xprime=zeros(4,1);
%here we create a blank column vector that we can add elements to.
c = -(6.67e-11)*(5.97e24);
%here we define our constant c, -GM, which we can plug numbers in for the Earth.
xprime(1) = x(2); %vx
xprime(2) = (c.*x(1))./(((x(1).^2)+(x(3).^2)).^(3/2)); %dvx/dt
xprime(3) = x(4); %vy
xprime(4) = (c.*x(3))./(((x(1).^2)+(x(3).^2)).^(3/2));%dvy/dt
%here we have the differential equations d2x/dt2 = -GM/r^2 cos(theta) and d2y/dt2 = -GM/r^2 sin(theta) where cos(theta) and sin(theta) are x/r and y/r respectively.
%we split these two second order ODEs into systems of two first order ODEs by introducing new variables to represent the first derivatives, vx and vy.
%then we add the differential equations to our xdot column vector.
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We can then use matlab's ODE45 function to solve, and plot. Easy as that! This is one of the simplest cases, of course, since mass divides out of our equations.
But here's my dilema; I want to extrapolate this code for a Rocket ascending from the ground on the Earth. Our ODEs will still require Newton's law, but our equations for force will be different, and of course mass doesn't divide out since mass is changing with time dm/dt.
Our ODEs will now be a function of gravity (which we can assume to be constant), drag (which is a function of speed) and thrust (which can be assumed to be constant)
So I would like some help with incorporating changing mass into our ODEs. I believe I can most of what I've done above, but I'm unsure how to change/add the ODEs to incorporate the changing mass.
I'd also like it in 2-dimensions as I've done above. Can anyone help me with this?
We start with Newton's 2nd law and use the equation a=F/m in freespace (so m can divide out) to get a 2nd order ODE and solve by separating them into systems of first order ODEs.
Here's my code for this program:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function xprime = rocketODE(t,x)
%creating a function called roketODE that will solve for a system of first order ODEs of a rocket's motion around the Earth (at the origin)
xprime=zeros(4,1);
%here we create a blank column vector that we can add elements to.
c = -(6.67e-11)*(5.97e24);
%here we define our constant c, -GM, which we can plug numbers in for the Earth.
xprime(1) = x(2); %vx
xprime(2) = (c.*x(1))./(((x(1).^2)+(x(3).^2)).^(3/2)); %dvx/dt
xprime(3) = x(4); %vy
xprime(4) = (c.*x(3))./(((x(1).^2)+(x(3).^2)).^(3/2));%dvy/dt
%here we have the differential equations d2x/dt2 = -GM/r^2 cos(theta) and d2y/dt2 = -GM/r^2 sin(theta) where cos(theta) and sin(theta) are x/r and y/r respectively.
%we split these two second order ODEs into systems of two first order ODEs by introducing new variables to represent the first derivatives, vx and vy.
%then we add the differential equations to our xdot column vector.
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We can then use matlab's ODE45 function to solve, and plot. Easy as that! This is one of the simplest cases, of course, since mass divides out of our equations.
But here's my dilema; I want to extrapolate this code for a Rocket ascending from the ground on the Earth. Our ODEs will still require Newton's law, but our equations for force will be different, and of course mass doesn't divide out since mass is changing with time dm/dt.
Our ODEs will now be a function of gravity (which we can assume to be constant), drag (which is a function of speed) and thrust (which can be assumed to be constant)
So I would like some help with incorporating changing mass into our ODEs. I believe I can most of what I've done above, but I'm unsure how to change/add the ODEs to incorporate the changing mass.
I'd also like it in 2-dimensions as I've done above. Can anyone help me with this?