Please include all result comments, comment on code and both questions for upvot
ID: 3745248 • Letter: P
Question
Please include all result comments, comment on code and both questions for upvote. Thanks!!
Problem 2: Having eliminated unacceptable launch times, our rocket is ready to launch. Let us assume the following launch dynamics dv m(t) =-m(t)o-cam dt where m(t) is the mass of the rocket, g 9.81 m/s is gravitational acceleration, and c is some constant Let us assume the rocket uses fuel at a constant rate of dm/dt =-100 kg/s, the initial mass is m(0) 380,000 kg, and c 25,000 m/s. Write a MATLAB function called rocket_euler to solve this o.d.e. from t0 seconds tot 600 seconds using Euler's method. Make the step size the input for the function, and make the time, mass, and velocity vectors the outputsExplanation / Answer
problem 2:-
function [ velocity ] = rocket_euler( )
%ROCKET_EULER
m0=380000; %intial mass
c=25000;
dmdt=-400; %fuel use rate
g=9.81;
tn=600;
n=1000;
th=linspace(0,tn,n); %time from 0sec to 600sec is divided by particular step size
h=(tn-0)/n; %step-size
velocity=[]; %array to store velocity at each time
y=0; %assume initial velocity equals 0
%Euler Method
%yn+1 = yn + h * f(xn, yn) where n varies from 0 to iteration value
for i=1:n
y=y+(h*dvdt(th(i),g,c,m0,dmdt));
velocity = [velocity y];
end
end
problem 3:-
v = rocket_euler();
t = linspace(0,600, 1000);
m0=380000; %intial mass
c=25000;
dmdt=-400; %fuel use rate
g=9.81;
mt=m0-400*t;
de=log10(mt/m0)/log10(exp(1));
vt=-1*g*t-c*de;
figure(1);
subplot(211)
plot(t, v,'b');
title('Velocity vs Time Plot');
xlabel('Time in seconds');
ylabel('Velocity in m/s');
grid on;
subplot(212);
plot(t, vt,'r');
title('Velocity vs Time Plot');
xlabel('Time in seconds');
ylabel('Velocity in m/s');
%legend('velocity from euler method', 'analytical soln of velocity');
%The difference between the values of euler solutions and analytical values is very small. The graph %is almost similar when plotted.