MATLAB: Calculate the speed and position of the rocket and plot a graph of velocity vs time and altitude vs time

differential equationsfor loopif statementplotprojectiletrajectory

1::: m*dV/dt= v_e*dm/dt -G*Mm/r^2 -0.5ρAV^2 C_d
2::: ρ=1.225*10^(-3h/50000)
i need to plot a graph of speed against time using equation 1. I am not allowed to use matlab function to solve the differential eqaution such as ode45, or dsolve instead i need to use explicit method. Also I need to plot a graph of altitude against time
This is my code so far
I am stuck and don't know what to do next? please help
clear
speed(1)=v;
speed_2(1)=v;
height(1)=h;
height_2(1)=h;
mass(1)=m_0;
radii(1)=R;
rho(1)=rho_0;
drag(1)=D;
thrust(1)=T;
weight(1)=w_0;
%CONSTANTS
G=6.67408*10^(-11);
M=5.9722*10^(24);
R=6371000;
gravity= 9.81;
A= 75;
c_d=0.4;
v_e=4500;
dt=1;
m_e=54000;
m_0=894000;
dm=5000;
dm_2=0;
tNfuel=(m_0/m_e)/dm;
%INITAL VALUE AT t=0
v=0;
r=R;
h=0;
rho_0=1.225;
D=0;
T=0;
w_0=(G*M*m_0)/(R^2);
%GIVEN EQUATION
for i=2:lenght(t)
rho(i)=1.225(1)*10^((-3*h(i-1)/50000);
if m(i-1)>=m_e
m(i)=m(i-1)- dm*dt;
else
m(1)=m(i-1);
dm=0;
end
end
plot(v,t)

Best Answer

It seems like you are trying to use Euler's method. If you are confused about implementing the numerical ODE solver from scratch, then look at the code of ode1.m, which is an old MATLAB solver based on the Euler method: https://www.mathworks.com/matlabcentral/answers/98293-is-there-a-fixed-step-ordinary-differential-equation-ode-solver-in-matlab-8-0-r2012b. It is no longer available in MATLAB. You can adapt according to your ODEs.