22
Appendix C ————————————————————– MATLAB Codes This appendix is to provide the reader with MATLAB codes, which, when applied, generate directly the results for the test cases of the book. The standard word length for computations with the MATLAB software amounts to 64 bit. The SI units are used throughout this book, Appendix D. All the MATLAB codes listed in this appendix can be downloaded from http://extra.springer.com. C.1 Kepler’s Equation for Elliptical Orbits Program code for the numerical iteration of Kepler’s equation (first solution approach) applied to the elliptical problem defined in Section 5.7.2. % **************************************************************** % Solution of the orbit equation: Theta as function of time t. % Numerical solution of Kepler’s equation for the elliptical test problem of % Section 5.7.2 (first solution approach). % **************************************************************** tp = 0.; eps = 1.e-5; T = 58285.7; dT = 100.; kend = T/dT; theta = 0.2; e = 0.8; for k = 1:kend t1(k) = k*dt; tau = 2*pi*(t1(k)-tp)/T; dE = 0.1; E0 = 0.1; while dE > eps FE = E0 - e*sin(E0) - tau; dFE = 1. -e*cos[E0); E1 = E0 - FE/dFE;

Appendix C ————————————————————– MATLAB Codesextras.springer.com/2010/978-3-642-13582-8/Appendix C/MATLAB.pdf · 268 Appendix C MATLAB Codes

  • Upload
    others

  • View
    26

  • Download
    0

Embed Size (px)

Citation preview

Appendix C————————————————————–MATLAB Codes

This appendix is to provide the reader with MATLAB codes, which, whenapplied, generate directly the results for the test cases of the book.

The standard word length for computations with the MATLAB softwareamounts to 64 bit. The SI units are used throughout this book, Appendix D.All the MATLAB codes listed in this appendix can be downloaded fromhttp://extra.springer.com.

C.1 Kepler’s Equation for Elliptical Orbits

Program code for the numerical iteration of Kepler’s equation (first solutionapproach) applied to the elliptical problem defined in Section 5.7.2.

% ****************************************************************% Solution of the orbit equation: Theta as function of time t.% Numerical solution of Kepler’s equation for the elliptical test problem of% Section 5.7.2 (first solution approach).% ****************************************************************

tp = 0.;eps = 1.e-5;T = 58285.7;dT = 100.;kend = T/dT;theta = 0.2;e = 0.8;

for k = 1:kendt1(k) = k*dt;tau = 2*pi*(t1(k)-tp)/T;dE = 0.1;E0 = 0.1;

while dE > epsFE = E0 - e*sin(E0) - tau;dFE = 1. -e*cos[E0);E1 = E0 - FE/dFE;

262 Appendix C MATLAB Codes

dE = abs(E1 - E0);E0 = E1;end

theta(k) = 2.*atan(sqrt((1+e)/(1-e))*tan(E0/2));

if theta(k) < 0theta(k) = 2.*pi + theta(k);end

thgrad(k) = theta(k)*180/pi;end

% ****************************************************************% Plotting the result% ****************************************************************

figure(1)plot(t1,thgrad,’-k’,’Linewidth’,2)xlabel(’flight time [s]’,’Fontweight’,’bold’,’Fontsize’,12)ylabel(’true anomaly theta [◦]’,’Fontweight’,’bold’,’Fontsize’,12)grid onaxis([0 60000 0 400])

% ****************************************************************% End of programme% ****************************************************************

C.2 Area Approach for Elliptical Orbits 263

C.2 Area Approach for Elliptical Orbits

Program code for the numerical iteration of the area approach (second so-lution approach) applied to the elliptical problem defined in Section 5.7.2.Numerical solution of eqs. (5.46) and (5.47) by using a Newton iterationprocess.

% ****************************************************************% Solution of the orbit equation: Theta as function of time t.% Numerical solution of the simple area approach for the elliptical% test problem of Section 5.7.2 (second solution approach).% ****************************************************************

tp = 0.;eps = 1.e-5;T = 58285.7;dT = 100.;kend = T/dT;theta = 0.2;e = 0.8;a = 32.5e+6;b = 19.5e+6;p = 11.7e+6;f = 6.8318e+10;

for k = 1:kendt1(k) = k*dt;dtheta = 0.1;

nit = 0;

% ****************************************************************% Iteration for 0 ≤ θ ≤ π% ****************************************************************

if theta0 < piwhile dtheta > epsr = p/(1+e*cos(theta0));dr = r*e*sin(theta0)/(1+e*cos(theta0));x = a*e + r*cos(theta0);dx = -r*sin(theta0)+dr*cos(theta0);Ft = r*a*e*sin(theta0) - a*b*acos(x/a) + f*(t1(k) - tp);dFt = a*e*(dr*sin(theta0) + r*cos(theta0)+ ...b*dx/(sqrt(1-(x/a)**2));

264 Appendix C MATLAB Codes

theta1(k) = theta0 - Ft/dFt;dtheta = abs(theta1(k) - theta0);theta0 = theta1(k);nit = nit + 1;if nit > 500breakendend

else

% ****************************************************************% Iteration for π ≤ θ ≤ 2π% ****************************************************************

while dtheta > epsr = p/(1+e*cos(theta0));dr = r*e*sin(theta0)/(1+e*cos(theta0));x = a*e + r*cos(theta0);dx = -r*sin(theta0)+dr*cos(theta0);Ft = r*a*e*sin(theta0) + a*b*acos(x/a) + f*(t1(k) - tp)...-2*pi*a*b;dFt = a*e*(dr*sin(theta0) + r*cos(theta0)- ...b*dx/(sqrt(1-(x/a)**2));theta1(k) = theta0 - Ft/dFt;dtheta = abs(theta1(k) - theta0);theta0 = theta1(k);nit = nit + 1;if nit > 500breakendendend

thgrad(k) = theta1(k)*180/pi;end

% ****************************************************************% Plotting the result% ****************************************************************

figure(1)plot(t1,thgrad,’-k’,’Linewidth’,2)xlabel(’flight time [s]’,’Fontweight’,’bold’,’Fontsize’,12)ylabel(’true anomaly θ [◦]’,’Fontweight’,’bold’,’Fontsize’,12)

C.2 Area Approach for Elliptical Orbits 265

grid onaxis([0 60000 0 400])

% ****************************************************************% End of programme% ****************************************************************

266 Appendix C MATLAB Codes

C.3 Area Approach for Hyperbolic Orbits

Program code for the numerical iteration of Kepler’s equation (second solu-tion approach) applied to the hyperbolic problem defined in Section 5.7.4.Numerical solution of eq. (5.52).

%*****************************************************************% Solution of the orbit equation: Theta as function of time.% Numerical solution of the second solution approach for the% hyperbolic problem test case 3 of Section 5.7.4 .%*****************************************************************

tp = 0.;eps = 1e-5;dT = 100;Tend = 60000;kend = Tend/dT;dtheta = 0.005*pi/180;thetamax = 131.81*pi/180;jend = thetamax/dtheta;

e = 1.5;a = 13.0e+6;p = 16.25e+6;gamma = 3.9892e+14;f = 8.05137e+10;

da2(1) = 0;for j=1:jendtheta(j+1) = j*dtheta;ri(j) = p/(1+e*cos(theta(j+1)));dda2 = 0.5*ri(j)**2*dtheta;da2(j+1) = da2(j) + dda2;end

for k=1:kendt1(k) = k*dT;da1 = 0.5*(t1(k)-tp)*f;j = 1;while da1 > da2(j+1)j = j + 1;end

C.3 Area Approach for Hyperbolic Orbits 267

thgrad(k) = theta(j+1)*180/pi;

end

figure(1)plot(t1,thgrad,’-k’,’Linewidth’,2)xlabel(’flight time [s]’,’FontWeight’,’bold’,’FontSize’,14)ylabel(’true anomaly θ [◦]’,’FontWeight’,’bold’,’FontSize’,14)grid onaxis([0 60500 0 150])

% ****************************************************************% End of programme% ****************************************************************

268 Appendix C MATLAB Codes

C.4 Six Degree of Freedom Simulation

Program code for the numerical integration of the general translational androtational equations of planetary flight in body fixed coordinates. Six degreeof freedom simulations. The set of 12 ordinary differential equations, namelythe eqs. (6.60), (6.66), (6.69) and (6.70), defined in Section 6.3, is numericallysolved. Further information regarding the set of equations can be found in[1] - [5]. See also Section 8.3.

The program code is furnished with the conditions of the example of Sub-Section 8.3.2.

The output file ”X-38 six degrees 1.txt” contains in the following order:

the time t (’time’), the velocity V (’velocity’), the flight path angle γ(’gamma’), the angle of attack α (’alfa’), the Euler angle θ′ (’thetas’), theEuler angle ψ′ (’psis’), the longitude angle θ (’theta’), the latitude angle φ(’phi’), the altitude H (’alt’) and the angle of yaw β (’beta’).

The output file ”X-38 Aero six degrees 1.txt” contains in the followingorder:

the lift coefficient CL (’lift’), the drag coefficient CD (’drag’) and the pitchingmoment coefficient Cm (’pitch’).

The data files ’pitch.txt’, ’yaw.txt’, ’lift.txt’, ’drag.txt’, ’sideforce.txt’ inthe subroutine ”Function for Assignment of Constant Values” reflect thevalues given in Figs. 7.7, 7.8, 7.9, 7.11, 7.12 for ηbf = 20◦ and can also bedownloaded from the internet address: http://extra.springer.com.

% =========================================% Main Program% Integrating of Translational and Rotational Governing% Equations of Flight Mechanics; Six Degree of Freedom% Body Fixed Coordinates.% =========================================

tstart=clock;

[m,Sref,Lref,rhos,gs,bet,omegae,rearth,V00,a1X,CmX,...CLX,CDX,b1X,CyX,CnX]...=constants;

% ********************************************************% Time Parameter% ********************************************************

arc = pi/180.;t0 = 0.;

C.4 Six Degree of Freedom Simulation 269

tend1 = 989.;tspan = [t0 tend1];

% ********************************************************% Initial Conditions% ********************************************************

[un,vn,wn,phisn,thetasn,psisn,hn,phin,thetan]...=initiala;

[omb,ome]...=initialb(un,vn,wn,phisn,thetasn,psisn,hn,phin,thetan,omegae);

pn = omb(1) + ome(1);qn = omb(2) + ome(2);rn = omb(3) + ome(3);

% ********************************************************% Integration Loop% ********************************************************

y0(1)= un;y0(2)= vn;y0(3)= wn;y0(4)= pn;y0(5)= qn;y0(6)= rn;y0(7)= phisn;y0(8)= thetasn;y0(9)= psisn;y0(10)= hn;y0(11)= phin;y0(12)= thetan;

options = odeset(’Maxstep’,1);

[t,y]=ode23(@RHS,tspan,y0,options);

un = y(:,1);vn = y(:,2);wn = y(:,3);pn = y(:,4);qn = y(:,5);rn = y(:,6);phisn = y(:,7);

270 Appendix C MATLAB Codes

thetasn = y(:,8);psisn = y(:,9);hn = y(:,10);phin = y(:,11);thetan = y(:,12);

% ********************************************************% Evaluation of Data and Plot Preparation% ********************************************************

elem = size(un);iend = elem(1);

nn = 1;

for i = 1:4:iend

[Maero,Vabs,Mg,alfa,beta]...=matrices(un(i),vn(i),wn(i),phisn(i),thetasn(i),psisn(i));

rgn(i) = hn(i) + rearth;

[A,M,MG1,CL(i),CD(i),Cm(i)]...=aerodynamics(hn(i),Maero,Vabs,rgn(i),Mg,alfa,beta);

V1(1) = un(i);V1(2) = vn(i);V1(3) = wn(i);

V1g = Mg’*V1’;

gamma(i) =-asin(V1g(3)/Vabs);chi(i) = atan(V1g(2)/V1g(1));

if V1g(1) < 0.chi(i) = pi + atan(V1g(2)/V1g(1));end

alfagr(i) = alfa/arc;betagr(i) = beta/arc;thetsgr(i) = thetasn(i)/arc;thetgr(i) = thetan(i)/arc;psisgr(i) = psisn(i)/arc;phigr(i) = phin(i)/arc;

C.4 Six Degree of Freedom Simulation 271

gammagr(i) = gamma(i)/arc;chigr(i) = chi(i)/arc;Vmag(i) = Vabs;h(i) = hn(i);

result(nn,1) = t(i);result(nn,2) = Vmag(i);result(nn,3) = gammagr(i);result(nn,4) = alfagr(i);result(nn,5) = thetsgr(i);result(nn,6) = psisgr(i);result(nn,7) = thetgr(i);result(nn,8) = phigr(i);result(nn,9) = h(i);result(nn,10)= betagr(i);

result1(nn,1) = t(i);result1(nn,2) = CL(i);result1(nn,3) = CD(i);result1(nn,4) = Cm(i);

nn = nn+1;

end

% ********************************************************% Generation of Files for Plotting the Results% ********************************************************

fid = fopen(’X-38 six degrees 1.txt’,’w’);fprintf(fid,’time velocity gamma alfa thetas psis theta phi alt beta \n \n’);fprintf(fid,’%4.0f %13.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %13.4f%10.4f \n’,result’);status = fclose(fid);

fid = fopen(’X-38 Aero six degrees 1.txt’,’w’);fprintf(fid,’lift drag pitch \n \n’);fprintf(fid,’%4.0f %11.5f %11.5f %11.7f \n’,result1’);status = fclose(fid);

% ****************************************************************% End of Main Program% ****************************************************************

272 Appendix C MATLAB Codes

% =========================================% Sub Program% Providing the Right Hand Sides of the Differential% Equation dy/dt= by Gauss Elimination of A y(t) = B.% Actual State: Equations with Earth Rotation Terms% =========================================

function dydt=RHS(t,y)

[m,Sref,Lref,rhos,gs,bet,omegae,rearth,V00,a1X,CmX,...CLX,CDX,b1X,CyX,CnX]...=constants;

[T] = inertia;

u1 = y(1);v1 = y(2);w1 = y(3);p1 = y(4);q1 = y(5);r1 = y(6);phis1 = y(7);thetas1 = y(8);psis1 = y(9);h1 = y(10);phi1 = y(11);theta1 = y(12);

[Maero,Vabs,Mg,alfa,beta]...=matrices(u1,v1,w1,phis1,thetas1,psis1);

rg1 = h1 + rearth;

[A,M,MG1,CL,CD,Cm]...=aerodynamics(h1,Maero,Vabs,rg1,Mg,alfa,beta);

% ********************************************************% Establishment of Elimination Matrix AA% ********************************************************

AA=zeros(6,6);AA(1,1)= m;AA(2,2)= m;AA(3,3)= m;

C.4 Six Degree of Freedom Simulation 273

AA(4,4)= T(1,1);AA(4,6)= T(1,3);AA(5,5)= T(2,2);AA(6,4)= T(3,1);AA(6,6)= T(3,3);

om1(1) = cos(phi1)*omegae;om1(2) = 0.;om1(3) = -sin(phi1)*omegae;

omb = Mg*om1’;

pb = omb(1);qb = omb(2);rb = omb(3);

ommat= zeros(3,3);ommat(1,2) = -rb;ommat(1,3) = qb;ommat(2,1) = rb;ommat(2,3) = -pb;ommat(3,1) = -qb;ommat(3,2) = pb;

ommat2 = ommat*ommat;

rg1v(1) = 0.;rg1v(2) = 0.;rg1v(3) = rg1;

rg1vb = Mg*rg1v’;

centripetal = -ommat2*rg1vb;

V1(1) = u1;V1(2) = v1;V1(3) = w1;

V1g = Mg’*V1’;

gamma = -asin(V1g(3)/Vabs);chi = atan(V1g(2)/V1g(1));

274 Appendix C MATLAB Codes

if V1g(1) < 0.chi = pi + atan(V1g(2)/V1g(1));end

h1p = Vabs*sin(gamma);phi1p = Vabs*cos(gamma)*cos(chi)/rg1;theta1p = Vabs*cos(gamma)*sin(chi)/(rg1*cos(phi1));

om2(1) = theta1p*cos(phi1);om2(2) =-phi1p;om2(3) =-theta1p*sin(phi1);

ome = Mg*om2’;

pe = ome(1);qe = ome(2);re = ome(3);

% ***************************************************************% Set up of Right Hand Side (The Inhomogeneous part of the ODE)% ***************************************************************

BB(1)=A(1)+MG1(1)-m*(q1*w1-r1*v1)-m*(qb*w1-rb*v1) - m*centripetal(1);BB(2)=A(2)+MG1(2)-m*(r1*u1-p1*w1)-m*(rb*u1-pb*w1) - m*centripetal(2);BB(3)=A(3)+MG1(3)-m*(p1*v1-q1*u1)-m*(pb*v1-qb*u1) - m*centripetal(3);BB(4)=M(1)-T(1,3)*p1*q1+(T(2,2)-T(3,3))*q1*r1;BB(5)=M(2)-T(1,3)*(r12-p12)+ (T(3,3)-T(1,1))*r1*p1;BB(6)=M(3)-T(1,3)*q1*r1+(T(1,1)-T(2,2))*p1*q1;

X=inv(AA)*BB’;

pp1 = p1 - pb - pe;qq1 = q1 - qb - qe;rr1 = r1 - rb - re;

% ***************************************************************% Rate of Change of the Euler Angles Describing the Attitude% of the Space Vehicle% ***************************************************************

phis1p = pp1+sin(phis1)*tan(thetas1)*qq1+cos(phis1)*tan(thetas1)*rr1;thetas1p = cos(phis1)*qq1-sin(phis1)*rr1;psis1p = sin(phis1)/cos(thetas1)*qq1+cos(phis1)/cos(thetas1)*rr1;

C.4 Six Degree of Freedom Simulation 275

% ***************************************************************% Completion of the Set of the 12 Ordinary Differential Equations% ***************************************************************

dydt=X;

dydt(7) = phis1p;dydt(8) = thetas1p;dydt(9) = psis1p;dydt(10) = h1p;dydt(11) = phi1p;dydt(12) = theta1p;

% ****************************************************************% End of Sub Program RHS% ****************************************************************

% =========================================% Function Aerodynamics% Provision of Aerodynamic Forces and Moments in Body Fixed% Coordinates% =========================================

function [A,M,MG1,CL,CD,Cm]...=aerodynamics(h,Maero,Vabs,rg1,Mg,alfa,beta);

[m,Sref,Lref,rhos,gs,bet,omegae,rearth,V00,a1X,CmX,...CLX,CDX,b1X,CyX,CnX]...=constants;

arc = pi/180.;

% ********************************************************% Generation of Aerodynamics of Space Vehicle% ********************************************************

rho = rhos*exp(-bet*h);g = gs*(rearth/rg1)∗ ∗ 2;

norm = rho/2.*Vabs∗ ∗ 2*Sref;

algr = alfa/arc;begr = beta/arc;

276 Appendix C MATLAB Codes

% ********************************************************% Bank Angle Factor% ********************************************************

mue = 0.4

% ********************************************************% X-38 Longitudinal and Lateral Aerodynamics% ********************************************************

CL = interpl(a1X,CLX,algr,’cubic’)*mue;CD = interpl(a1X,CDX,algr,’cubic’);Cm = interpl(a1X,CmX,algr,’cubic’);CQ = interpl(b1X,CyX,begr,’cubic’);Cn = interpl(b1X,CnX,begr,’cubic’);

Cll = 0.;

aa(1) = -CD;aa(2) = CQ;aa(3) = -CL;

A = norm*Maero*aa’;

ma(1) = Cll*Lref;ma(2) = Cm *Lref;ma(3) = Cn *Lref;

M = norm*ma’;

G(1) = 0.;G(2) = 0.;G(3) = m*g;

MG1=Mg*G’;

% ****************************************************************% End of Function Aerodynamics% ****************************************************************

C.4 Six Degree of Freedom Simulation 277

% =========================================% Function ”Matrices” Creates the Transformation Matrices% =========================================

function [Maero,Vabs,Mg,alfa,beta]...=matrices(u1,v1,w1,phis1,thetas1,psis1);

Vabs=sqrt(u1.*u1+v1.*v1+w1.*w1);

uvb = sqrt(u1.*u1+v1.*v1);alfa = atan(w1/uvb);beta = atan(v1/u1);

% ********************************************************% Matrix Transforming from Aerodynamic to Body Fixed System% ********************************************************

Maero(1,1) = cos(alfa)*cos(beta);Maero(1,2) =-cos(alfa)*sin(beta);Maero(1,3) =-sin(alfa);Maero(2,1) = sin(beta);Maero(2,2) = cos(beta);Maero(2,3) = 0.;Maero(3,1) = sin(alfa)*cos(beta);Maero(3,2) =-sin(alfa)*sin(beta);Maero(3,3) = cos(alfa);

% ********************************************************% Matrix Transforming from Geodetic to Body Fixed System% ********************************************************

Mg(1,1) = cos(psis1)*cos(thetas1);Mg(1,2) = sin(psis1)*cos(thetas1);Mg(1,3) =-sin(thetas1);Mg(2,1) = sin(phis1)*sin(thetas1)*cos(psis1) - cos(phis1)*sin(psis1);Mg(2,2) = sin(phis1)*sin(thetas1)*sin(psis1) + cos(phis1)*cos(psis1);Mg(2,3) = sin(phis1)*cos(thetas1);Mg(3,1) = cos(phis1)*sin(thetas1)*cos(psis1) + sin(phis1)*sin(psis1);Mg(3,2) = cos(phis1)*sin(thetas1)*sin(psis1) - sin(phis1)*cos(psis1);Mg(3,3) = cos(phis1)*cos(thetas1);

% ****************************************************************% End of Function Matrices% ****************************************************************

278 Appendix C MATLAB Codes

% =========================================% Function ”Initiala” Provides and Generates Intitial Data% =========================================

function [u1,v1,w1,phisn,thetasn,psisn,hn,phin,thetan]...=initiala;

% ********************************************************% Matrix Transforming from Geodetic to Body Fixed System% ********************************************************

arc = pi/180.;

Vtot = 7606.28;chie = -2.6022*arc;gamma = -3.0*arc;phisn = 0.*arc;thetasn = 27.0*arc;psisn = 90.*arc;hn = 121920;phin = 0.;thetan = 0.;

Mg(1,1) = cos(psisn)*cos(thetasn);Mg(1,2) = sin(psisn)*cos(thetasn);Mg(1,3) =-sin(thetasn);Mg(2,1) = sin(phisn)*sin(thetasn)*cos(psisn) - cos(phisn)*sin(psisn);Mg(2,2) = sin(phisn)*sin(thetasn)*sin(psisn) + cos(phisn)*cos(psisn);Mg(2,3) = sin(phisn)*cos(thetasn);Mg(3,1) = cos(phisn)*sin(thetasn)*cos(psisn) + sin(phisn)*sin(psisn);Mg(3,2) = cos(phisn)*sin(thetasn)*sin(psisn) - sin(phisn)*cos(psisn);Mg(3,3) = cos(phisn)*cos(thetasn);

uvg = cos(gamma)*Vtot;Vg(1) = uvg*sin(chie);Vg(3) = -sin(gamma)*Vtot;Vg(2) = uvg*cos(chie);

Vb = Mg*Vg’;

u1 = Vb(1);v1 = Vb(2);w1 = Vb(3);

% ****************************************************************% End of Function Initiala% ****************************************************************

C.4 Six Degree of Freedom Simulation 279

% =========================================% Function ”Initialb” Generates Intitial Data for Omega% =========================================

function [omb,ome]...=initialb(u1,v1,w1,phis1,thetas1,psis1,h1,phi1,theta1,omegae);

[m,Sref,Lref,rhos,gs,bet,omegae,rearth,V00,a1X,CmX,...CLX,CDX,b1X,CyX,CnX]...=constants;

% ********************************************************% Matrix Transforming from Geodetic to Body Fixed System% ********************************************************

Vabs=sqrt(u1.*u1+v1.*v1+w1.*w1);rg1 = h1 + rearth;

Mg(1,1) = cos(psis1)*cos(thetas1);Mg(1,2) = sin(psis1)*cos(thetas1);Mg(1,3) =-sin(thetas1);Mg(2,1) = sin(phis1)*sin(thetas1)*cos(psis1) - cos(phis1)*sin(psis1);Mg(2,2) = sin(phis1)*sin(thetas1)*sin(psis1) + cos(phis1)*cos(psis1);Mg(2,3) = sin(phis1)*cos(thetas1);Mg(3,1) = cos(phis1)*sin(thetas1)*cos(psis1) + sin(phis1)*sin(psis1);Mg(3,2) = cos(phis1)*sin(thetas1)*sin(psis1) - sin(phis1)*cos(psis1);Mg(3,3) = cos(phis1)*cos(thetas1);

om1(1) = cos(phi1)*omegae;om1(2) = 0.;om1(3) = -sin(phi1)*omegae;

omb = Mg*om1’;

V1(1) = u1;V1(2) = v1;V1(3) = w1;

V1g = Mg’*V1’;

gamma =-asin(V1g(3)/Vabs);chi = atan(V1g(2)/V1g(1));

if V1g(1) < 0.chi = pi + atan(V1g(2)/V1g(1));end

280 Appendix C MATLAB Codes

h1p =-Vabs*sin(gamma);phi1p = Vabs*cos(gamma)*cos(chi)/rg1;theta1p = Vabs*cos(gamma)*sin(chi)/(rg1*cos(phi1));

om2(1) = theta1p*cos(phi1);om2(2) =-phi1p;om2(3) =-theta1p*sin(phi1);

ome = Mg*om2’;

% ****************************************************************% End of Function Initialb% ****************************************************************

% =========================================% Function for Assignment of Inertia Matrix% X-38 Data Base% =========================================

function [T] = inertia

T(1,1) = 4932.;T(1,2) = 0.;T(1,3) =-3155.;T(2,1) = 0.;T(2,2) = 60338.;T(2,3) = 0.;T(3,1) =-3155.;T(3,2) = 0.;T(3,3) = 62561.;

% ****************************************************************% End of Function Inertia Matrix% ****************************************************************

% =========================================% Function for Assignment of Constant Values% =========================================

function [m,Sref,Lref,rhos,gs,bet,omegae,rearth,V00,a1X,CmX,...CLX,CDX,b1X,CyX,CnX]...=constants;

C.4 Six Degree of Freedom Simulation 281

pitch = load(’Pitch.txt’);yaw = load(’yaw.txt’);lift = load(’lift.txt’);drag = load(’drag.txt’);sideforce = load(’sideforce.txt’);

a1X = pitch(:,1);CmX = pitch(:,2);CLX = lift(:,2);CDX = drag(:,2);

b1X = sideforce(:,1);CyX = sideforce(:,2);CnX = yaw(:,2);

m = 9300;Sref = 21.672;Lref = 8.4088;rhos = 1.293;gs = 9.80665;bet = 0.000140845;omegae = 0.00007292;rearth = 6.38E6;V00 = 7606.28;

% ****************************************************************% End of Function Constants% ****************************************************************

282 Appendix C MATLAB Codes

References

1. Etkin, B.: Dynamics of Atmospheric Flight. John Wiley & Sons, New York(1972)

2. Wiesel, W.E.: Spaceflight Dynamics. McGraw-Hill Series in Aeronautical andAerospace Engineering, New York (1989)

3. Miele, A.: Flight Mechanics I, Theory of Flight Paths. Addison-Wesley, Reading(1962)

4. Vinh, N.X., Busemann, A., Culp, R.D.: Hypersonic and Planetary Entry FlightMechanics. The University of Michigan Press, Ann Arbor (1980)

5. Regan, F.J., Anandakrishnan, S.M.: Dynamics of Atmospheric Re-Entry. AIAAEducation Series, Washington, D.C. (1993)