Matlab 2nd order ODEs for Rocket Ascension

In summary, the conversation discusses a program written to simulate the trajectory of a rocket around the Earth with initial conditions that can be manipulated. The program uses Newton's 2nd law and a 2nd order ODE to solve for the motion of the rocket. The code for the program is provided and there is a discussion about incorporating changing mass and 2-dimensions into the simulation. The use of the rocket equation and numerical methods for solving ODEs is suggested to improve accuracy.
  • #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?
 
Physics news on Phys.org
  • #2


I think it's great that you have taken the initiative to write a program to simulate the motion of a rocket around the Earth. It's a great way to understand and visualize the complex dynamics involved in such a scenario.

In order to incorporate changing mass into your ODEs, you will need to use the concept of the rocket equation. This equation relates the change in velocity of a rocket to the ratio of its initial and final masses, and the specific impulse of the rocket engine. The specific impulse is a measure of the efficiency of the rocket engine and is a constant for a given engine.

So, your ODEs will have to take into account the thrust, drag, and gravity forces as well as the change in mass over time. You can use the rocket equation to calculate the change in velocity and incorporate it into your ODEs.

As for the 2-dimensional aspect, you can simply add another dimension to your position and velocity vectors, and modify your ODEs accordingly. This will allow you to simulate the motion of the rocket in 2-dimensions.

I would also suggest looking into numerical methods for solving ODEs, such as the Runge-Kutta method, as they can provide more accurate solutions compared to the ODE45 function.

Overall, it's great to see your enthusiasm for this project and I'm sure with some additional research and effort, you will be able to successfully incorporate changing mass and 2-dimensions into your program. Good luck!
 

Related to Matlab 2nd order ODEs for Rocket Ascension

1. How do I set up a second order ODE in Matlab for rocket ascension?

To set up a second order ODE in Matlab for rocket ascension, you will need to define the variables, initial conditions, and the differential equation that represents the rocket's motion. This can be done using the "ode45" or "ode15s" solver functions. You can also use other built-in functions such as "ode23" or "ode23t" depending on the specific problem.

2. Can I use symbolic variables in my second order ODE for rocket ascension in Matlab?

Yes, Matlab allows the use of symbolic variables in solving ODEs. You can use the "syms" function to define symbolic variables and then use them in your ODE equations. This can be particularly useful when solving complex rocket ascension problems with varying parameters.

3. How do I plot the results of my second order ODE for rocket ascension in Matlab?

To plot the results of your second order ODE for rocket ascension in Matlab, you can use the "ode45" solver function in conjunction with the "plot" function. This will generate a plot of the rocket's position, velocity, and acceleration over time. You can also use the "odeplot" function to customize the plot and add labels and titles.

4. Can I use different initial conditions in my second order ODE for rocket ascension in Matlab?

Yes, you can use different initial conditions in your second order ODE for rocket ascension in Matlab. You can specify the initial conditions when defining the ODE function or use the "setinit" function to change them after the ODE has been defined. This can be useful for simulating different scenarios or testing the sensitivity of the results to initial conditions.

5. How do I include external forces in my second order ODE for rocket ascension in Matlab?

You can include external forces in your second order ODE for rocket ascension in Matlab by adding them as additional terms in the ODE function. For example, if the rocket is experiencing thrust, you can include the thrust force as a term in the ODE equation. You can also include other external forces such as gravity, air resistance, or wind by adding their respective equations to the ODE function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
4
Views
565
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
7K
Replies
8
Views
299
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top