I need help on this in correcting my code This is what i hav

I need help on this in correcting my code.

This is what i have so far.

u = 2510;

M0 = 2.8*10.^6;

mdot = 13.3*10.^3;   

g = 9.81;

t = 0;

approxvalue= 0;

truevalue = 340;

while relerror <= 0.00001

t = t+1

v = u*(log(M0/((M0-mdot)*t)))-(g*t);

v = relerror

relerror = abs((truevalue-approxvalue)/(truevalue))

  

end

The speed of a rocket (v) moving vertically near the Earth\'s surface is approximated as: Mo v (t) u ln gt MO m In this equation, variable definition value 2510 m/s velocity of exhaust relative to rocket 2.8 x 106 kg mass of rocket at liftoff Mo 13.3 x 103 kg/s rate of fuel consumption 9.81 m/s2 acceleration due to gravity (near Earth surface) t time since liftoff in seconds Find the time at which the rocket reaches the speed of sound 340 m/s). Use any of the methods discussed in class (except MATLAB-provided functions). Solve until the relative approximation error is 0.00001. What would be the mass of the rocket at the time it reaches the speed of sound?

Solution

%matlab code

u = 2510;
M0 = 2.8*10.^6;
mdot = 13.3*10.^3;   
g = 9.81;
t = 0;
approxvalue= 0;
truevalue = 340;

relerror = abs((truevalue-approxvalue)/(truevalue));
while relerror > 0.00001
%increment time by 0.1 second
t = t+0.1;
% convert log to ln
l = log(M0/(M0-mdot*t))/log(exp(1));
v = u*(l)-(g*t);
% assign v to approx velocity
approxvalue = v;
relerror = ((truevalue-approxvalue)/(truevalue));
end

fprintf(\"Time: %d seconds\ \",t);
fprintf(\"Approx Velocity: %f m/s\ \",approxvalue);
% output:
% Time: 71.5 seconds
% Approx Velocity: 340.103033 m/s

I need help on this in correcting my code. This is what i have so far. u = 2510; M0 = 2.8*10.^6; mdot = 13.3*10.^3; g = 9.81; t = 0; approxvalue= 0; truevalue =
I need help on this in correcting my code. This is what i have so far. u = 2510; M0 = 2.8*10.^6; mdot = 13.3*10.^3; g = 9.81; t = 0; approxvalue= 0; truevalue =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site