# Need some basic help - Analyzing the Apollo 13 separation

2 views (last 30 days)
Fraser on 4 Apr 2012
I've recently been in communication with a NASA engineer regarding teh separation of the Command Module and the Lunar Module in the Apollo 13 mission. He has communicated the solution to me in a MatLab format. Unfortunately, I have little / no experience with MatLab. I am able to understand the majority of it, but some interpretation help would be appreciated.
I understand the majority of it (defining variables, making notes with %, etc.), but what I am struggling to comprehend are the WHILE and END commands, lines such as t(N)=0, or when variables are defined as
v2=v2+v2dot*dt;
Any help, interpretations, or pointers are most appreciated!
Thanks, Fraser
% APOLLO 13 SEPARATION
clear all
%DEFINITIONS
%D,L0 diameter and length of tunnel
%m1,m2 masses of CM and LM
%p0,rho0,T0 initial state of tunnel gas
%astar,rhostar, choked flow sound speed and density
%m=mass of gas in tunnel
%v1,v2 speeds of the CM and LM
%x separation distance
% DC discharge coefficient
%DATA
D= 1.29;%m
L0=0.54; %m
m2= 4547;%kg
m1= 5809;%kg
DC=0.85
R=259.8;%J/kg/degK
gamma=1.4; % for O2
T0= 223;%degK
p0= 1.34E4;% N/m^2; approx 2psi
rho0=p0/R/T0; %kg/m^3; approx 2/10 atm
rhostar=.6339*rho0;
astar=17.41*sqrt(T0);%m/s
%INITIAL VALUES
p=p0;
x=0;
S=0;
A = pi*D^2/4;
v1=0;
v2=0;
V0=A*L0;
m0=rho0*V0;
m=m0
N=1;
t(N)=0;
X(N)=0
%SOLVE EQUATIONS
A = pi*D^2/4;
f=p*A;
v1dot = f/m1;
v2dot=f/m2;
xdot=v1+v2;
V=V0+A*x;
Vdot=A*xdot;
mdot=-DC*S*rhostar*astar;
dt=.001; %sec.
%stop
while p/p0>.01
f=p*A;
v1dot = f/m1;
v1=v1+v1dot*dt;
v2dot=f/m2;
v2=v2+v2dot*dt;
xdot=v1+v2;
x=x+xdot*dt;
S=pi*D*x;
mdot=-DC*S*rhostar*astar;
m=m+mdot*dt;
rho=m/V;
v(N)=v1+v2;
P(N)=p;
X(N)=x;
XX=10*X;
t(N)=N*dt;
N=N+1;
end
v(N-1)
hold off
figure(1);
plot(t',P/p0')
xlabel('TIME,sec.')
ylabel('PRESSURE, p/p0')
figure(2)
hold off
plot(t',v');
xlabel('TIME,sec.')
ylabel('VELOCITY, m/s')
text (150,0.4 ,'x=5.25 cm.')
figure (3)
plot(t',v', t',P/p0', t',XX, 'linewidth',4)
xlabel('TIME,sec.')
text(0.09,0.58,'SEPARATION ')
text (0.09,0.53, 'SPEED, m/s.' )
text(0.09,0.39,'(SEPARATION ')
text (0.09,0.34, 'DIST.)/10, cm.' )
text(0.06,0.75, 'PRESSURE, p/po')
title('APOLLO13-LUNAR MODULE SEPARATION;p0=2psi')
Walter Roberson on 4 Apr 2012

Walter Roberson on 4 Apr 2012
The things you asked about are basic programming concepts common to the great majority of imperative programming languages.
t(N) = N*dt;
means to replace (or set) the N'th component of the vector "t" with the value of N multiplied by dt .
while CONDITION
block of statements
end
means that the portion between "while" and the corresponding "end" is a loop. In each iteration of the loop, the CONDITION is tested. If it is determined to be false, then the block of statements is skipped and the loop is exited, with evaluation continued with the next statement. If the condition is determined to be true, then the block of statements is executed another time and then control goes back to the top of the loop (so the condition is tested again, the block possibly executed again, and so on.)
v2=v2+v2dot*dt;
means that the current value of v2 is to be examined (as of the time the statement is started), and v2dot multiplied by dt is to be added to that value, and the result is written overtop of v2. The effect is to add v2dot*dt to the value stored in v2.
All imperative programming languages (e.g., C, Fortran, Pascal, COBOL, perl, and many many others) use this process of examining current values, calculating the expression, and storing the result in the designated location, just with different syntaxes. C and Fortran and perl use the same "=" syntax that MATLAB does. Pascal uses the token ":=" instead of "=", as in
v2:=v2+v2dot*dt;
and COBOL makes it tediously explicit with (e.g)
REPLACE v2 WITH v2+v2dot*dt
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 4 Apr 2012
Sorry I had a word wrong in the description of WHILE. I have fixed it.