Rocket Modeling Matlab Script

Off topic discussion zone.

Moderators: winston, another_commander, Cody

Post Reply
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Rocket Modeling Matlab Script

Post 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
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Re: Rocket Modeling Matlab Script

Post 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
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6312
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: Rocket Modeling Matlab Script

Post 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:
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Re: Rocket Modeling Matlab Script

Post 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.
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
User avatar
Gimbal Locke
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jan 08, 2012 11:32 pm
Location: Brussels
Contact:

Re: Rocket Modeling Matlab Script

Post by Gimbal Locke »

That's correct indeed: the unit of mass is kilogram, the unit of weight is Newton.
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Re: Rocket Modeling Matlab Script

Post 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).
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
NigelJK
Deadly
Deadly
Posts: 208
Joined: Tue Feb 16, 2010 5:07 pm
Location: Stockport, England

Re: Rocket Modeling Matlab Script

Post by NigelJK »

I believe this confusion was cited as a reason for Beagle 1 being lost ...
Post Reply