Page 1 of 1

Rocket Modeling Matlab Script

Posted: Tue Nov 20, 2012 7:13 am
by CommRLock78
I thought this might be fun to share, since it has to do with a rocket. This script is from an assignment and models a rocket that is accelerated for 0.15 seconds and has a parachute that opens when the velocity reaches -20 m/s (which we assume keeps the rocket at a constant -20 m/s until it hits the ground). We are also assuming no air resistance (other than the air resistance given by the parachute ;) ) and a constant mass for the rocket. The program asks to input the rocket's mass and the initial force applied on the rocket. The example the assignment gave was a rocket mass of 0.05 kg and an initial force of 16 Newtons, although you can use any numbers you like, so long as the initial force is sufficient enough to give an interesting performance (i.e., fly ;) ). As always, this works in GNU Octave, and octave tested = good :D.

Code: Select all

clear,clc
% Inputs for Rocket mass and Initial Applied Force
m = input('Enter mass of Rocket in kilograms: ');
Fi = input('Enter intial Force in Newtons: ');

% Constants and intial Acceleration, AO
g = 9.8;
A0 = (Fi - m*g)/m;

% Time the Parachute opens
P = 20/g + 0.15*A0/g +0.15;
% Time the Rocket hits the Ground
G = (0.5*A0*(0.15)^2 + A0*0.15*(P-0.15) - 0.5*g*(P)^2 + 0.15*g*P - 0.01125*g)/20 + P;

% Time matrix
t = 0:0.001:G;

% Empty y and v for piecewise function
y = nan*ones(size(t));
v = nan*ones(size(t));

% y(t) the height of the Rocket versus Time, t.
y(0<t & t<=0.15) = 0.5*A0.*t(0<t & t<=0.15).^2;
y(0.15<t & t<=P) = 0.5*A0*(0.15)^2 + A0*0.15.*(t(0.15<t & t<=P)-0.15) - 0.5*g.*t(0.15<t & t<=P).^2 + 0.15*g.*t(0.15<t & t<=P) - 0.01125*g;
y(P<t & t<=G) = 0.5*A0*(0.15)^2 + A0*0.15*(P-0.15) - 0.5*g*(P)^2 + 0.15*g*P - 0.01125*g - 20.*(t(P<t & t<=G)-P);

% y'(t) = v(t)
v(0<t & t<=0.15) = A0.*t(0<t & t<=0.15);
v(0.15<t & t<=P) = A0*0.15 - g.*t(0.15<t & t<=P) + 0.15*g;
v(P<t & t<=G) = -20 + 0.*t(P<t & t<=G);

% Plotting the results
subplot(2,1,1),plot(t,y);
title('y (height) versus t')
xlabel('time')
ylabel('y (height)')
subplot(2,1,2),plot(t,v);
title('v versus t')
xlabel('time')
ylabel('velocity')
shg

Re: Rocket Modeling Matlab Script

Posted: Tue Nov 20, 2012 8:39 pm
by CommRLock78
I made a couple changes, and now it prints out some interesting data as well :D .

Code: Select all

clear,clc
% Inputs for Rocket mass and Initial Applied Force
m = input('Enter mass of Rocket in kilograms: ');
Fi = input('Enter intial Force in Newtons: ');

% Constants and intial Acceleration, AO
g = 9.8;
A0 = (Fi - m*g)/m;
Wr = m*g;
Fnet = A0*m;
vM = 0.15*A0;

% Time the Parachute opens
P = 20/g + 0.15*A0/g + 0.15;
% Time the Rocket hits the Ground
G = (0.5*A0*(0.15)^2 + A0*0.15*(P-0.15) - 0.5*g*(P)^2 + 0.15*g*P - 0.01125*g)/20 + P;
% Time of Maximum height, H
M = 0.15*A0/g + 0.15;
H = 0.5*A0*(0.15)^2 + A0*0.15*(M-0.15) - 0.5*g*(M-0.15)^2;

% Time matrix
t = 0:0.001:G;

% Empty y and v for piecewise function
y = nan*ones(size(t));
v = nan*ones(size(t));

% y(t) the height of the Rocket versus Time, t.
y(0<t & t<=0.15) = 0.5*A0.*t(0<t & t<=0.15).^2;
y(0.15<t & t<=P) = 0.5*A0*(0.15)^2 + A0*0.15.*(t(0.15<t & t<=P)-0.15) - 0.5*g.*t(0.15<t & t<=P).^2 + 0.15*g.*t(0.15<t & t<=P) - 0.01125*g;
y(P<t & t<=G) = 0.5*A0*(0.15)^2 + A0*0.15*(P-0.15) - 0.5*g*(P)^2 + 0.15*g*P - 0.01125*g - 20.*(t(P<t & t<=G)-P);

% y'(t) = v(t)
v(0<t & t<=0.15) = A0.*t(0<t & t<=0.15);
v(0.15<t & t<=P) = A0*0.15 - g.*t(0.15<t & t<=P) + 0.15*g;
v(P<t & t<=G) = -20 + 0.*t(P<t & t<=G);

% Plotting the results
subplot(2,1,1),plot(t,y);
title('y (height) versus t')
xlabel('time')
ylabel('y (height)')
subplot(2,1,2),plot(t,v);
title('v versus t')
xlabel('time')
ylabel('velocity')
shg

% Printing out Interesting data
fprintf('The weight of the rocket is %0.2f Newtons.\n', Wr)
fprintf('The net force on the rocket is %0.2f Newtons.\n', Fnet)
fprintf('This initial acceleration given by the net force is %0.2f m/s^2.\n', A0)
fprintf('The rocket reaches a maximum height of %0.2f meters after %0.2f seconds.\n', H, M)
if P>G 
	fprintf('The rocket hits the ground after %0.2f seconds.\n', G)
else
if P<G
	fprintf('The parachute opens after %0.2f seconds.\n', P)
	fprintf('The rocket hits the ground after %0.2f seconds.\n', G)
end
end

Re: Rocket Modeling Matlab Script

Posted: Wed Nov 21, 2012 7:12 am
by Diziet Sma
CommRLock78 wrote:
I made a couple changes, and now it prints out some interesting data as well :D .

Code: Select all

fprintf('The weight of the rocket is %0.2f Newtons.\n', Wr)
Mass can be measured in Newtons now? :shock: :lol:

Re: Rocket Modeling Matlab Script

Posted: Wed Nov 21, 2012 9:36 am
by CommRLock78
Diziet Sma wrote:
Mass can be measured in Newtons now? :shock: :lol:
Last I checked, no, but force sure is, and weight is a force: the response of a mass to the acceleration due to gravity (as Newton described it, at any rate) ;)

Edit: Another way of thinking about it: weight is a vector, as it has direction, whereas mass is a scalar and thus, has no direction :D.

Re: Rocket Modeling Matlab Script

Posted: Thu Nov 22, 2012 9:00 pm
by Gimbal Locke
That's correct indeed: the unit of mass is kilogram, the unit of weight is Newton.

Re: Rocket Modeling Matlab Script

Posted: Thu Nov 22, 2012 11:52 pm
by CommRLock78
Gimbal Locke wrote:
That's correct indeed: the unit of mass is kilogram, the unit of weight is Newton.
Physics is so awesome :mrgreen: ... Universal truths. And SI provides a foundation for describing quantities between people who otherwise speak completely different languages.
Edit: Unfortunately, usage of the English system and frequent use of "pounds" causes some confusion on this front (although personally I never had a problem making the distinction, I know a few fellow students who did).

Re: Rocket Modeling Matlab Script

Posted: Tue Dec 04, 2012 3:41 pm
by NigelJK
I believe this confusion was cited as a reason for Beagle 1 being lost ...