Help with formulating conditional logic.
Show older comments
I am writing a stability and control code (for a class assignment) that takes into account 3 different airplane conditions; Climb data, Cruise data, and Approach data. I don't want to change variables for each condition, rather I have captured all of the data for each condition in the code with differing data for each condition.
Ultimately, I would like to output the transfer functions for each condition. I am not very savy with MATLAB and would love some help in finding the best way to formulate this logic.
The code:
clc
clear all
g = 32.174
theta1 = 0
%Cessna design parameters
S = 174 %Planform Area (ft^2)
c = 4.9 %Chord length (ft)
b = 36.0 %Wing span (ft)
%%%%%%%%%%%%%%%%Flight Conditions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Climb Flight Condition
altitude = 0
M = 0.120
U_1 = 133.5
q_bar = 21.2
c_frac = 26.2
a_1 = 5.4
%Cruise Flight Condition
h = 5000 %Altitude (ft)
M = 0.201 %Mach Number
U_1 = 220.1 %TAS (ft/s)
q_bar = 49.6 %Dynamic Pressure (lbs/ft^2)
c_frac = 26.4 %CG Location
a_1 = 0 %Angle of Attack (Deg)
%Approach Flight Condition
h = 0
M = 0.096
U_1 = 107.1
q_bar = 13.6
c_frac = 26.4
a_1 = 4
%%%%%%%%%%%%%%%%Mass Data For All Flight Conditions%%%%%%%%%%%%%%%%%%%%%%
%Mass Data in Climb, Cruise, and Approach Conditions
W = 2650 %Weight (lbs)
m = W/g %Mass
I_xx_B = 948 %Moment of Inertia along the X-axis (slug-ft^2)
I_yy_B = 1346 %Moment of Inertia along the Y-axis (slug-ft^2)
I_zz_B = 1967 %Moment of Inertia along the Z-axis (slug-ft^2)
I_xz_B = 0 %Moment of Inertia along the XZ plane (slug-ft^2)
%%%%%%%%%%%%%%%%%%%%%%%Longitudinal Control and Hinge Momoment $$$$$$$$$
%Climb Longitudinal Control and Hinge Moment Derivatives
Ch_a = -0.0545
Ch_del_e = -0.594
%Cruise Longitudinal Control and Hinge Moment Derivatives
Ch_a = -0.0584
Ch_del_e = -0.585
%Approach Longitudinal Control and Hinge Moment Derivatives
Ch_a = -0.0549
Ch_del_e = -0.594
%%%%%%%%%%%%%%%%%%%Lateral-Directional Stability%%%%%%%%%%%%%%%%%%%%
%Climb Lateral-Directional Stabillity Derivatives
Cl_B = -0.0895
Cl_p = -0.487
Cl_r = 0.1869
Cy_B = -0.404
Cy_p = -0.145
Cy_r = 0.267
Cn_B = 0.0907
Cn_TB = 0
Cn_p = -0.0649
Cn_r = -0.1199
%Cruise Lateral-Directional Stability Derivatives
Cl_B = -0.0923
Cl_p = -0.484
Cl_r = 0.0798
Cy_B = -0.393
Cy_p = -0.075
Cy_r = 0.214
Cn_B = 0.0587
Cn_TB = 0
Cn_p = -0.0278
Cn_r = -0.0937
%Approach Lateral-Directional Stability Derivatives
Cl_B = -0.0969
Cl_p = -0.494
Cl_r = 0.2039
Cy_B = -0.303
Cy_p = -0.213
Cy_r = 0.201
Cn_B = 0.0701
Cn_TB = 0
Cn_p = -0.0960
Cn_r = -0.1151
%%%%%%%%%%%%%%%%%%%%Lateral-Directional Control and Hing Moment%%%%%%%%%
%Climb Lateral-Directional Control and Hinge Moment Derivatives
Cl_dela = 0.229
Cl_delr = 0.0147
Cy_dela = 0
Cy_delr = 0.187
Cn_dela = -0.0504
Cn_delr = -0.0805
Ch_aa = 0
Ch_dela = -0.369
Ch_Br = 0.0819
Ch_delr = -0.579
%Cruise Lateral-Directional Control and Hinge Moment Derivatives
Cl_dela = 0.229
Cl_delr = 0.0147
Cy_dela = 0
Cy_delr = 0.187
Cn_dela = -0.0216
Cn_delr = -0.0645
Ch_aa = 0
Ch_dela = -0.363
Ch_Br = 0.0819
Ch_delr = -0.567
%Approach Lateral-Directional Control and Hinge moment Derivatives
Cl_dela = 0.229
Cl_delr = 0.0147
Cy_dela = 0
Cy_delr = 0.187
Cn_dela = -0.0504
Cn_delr = -0.0805
Ch_aa = 0
Ch_dela = -0.369
Ch_Br = 0.0819
Ch_delr = -0.579
%Lateral-Directional Dimensional Stability Derivatives
YB = (q_bar*S*Cy_B)/m
Yp = (S*b*Cy_p)/(2*m*U_1)
Yr = (q_bar*S*b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)+Yp*(L_delr+N_delr*A_1)...
+Yr*(L_dela*B_1+N_dela)+Yr*(L_delr*B_1+N_delr)-U_1*(L_dela*B_1+N_dela)...
+U_1*(L_delr*B_1+N_delr)
CB = Y_dela*(Lp*Nr-Np*Lr)+Y_delr*(Lp*Nr-Np*Lr)+Yp*(N_dela*Lr-L_dela*Nr)+Yp*(N_delr*Lr-L_delr*Nr)...
+g*cos(theta1)*(L_dela+N_dela*A_1)+g*cos(theta1)*(L_delr+N_delr*A_1)...
+Yr*(L_dela*Np-N_dela*Lp)+Yr*(L_delr*Np-N_delr*Lp)+U_1*(L_dela*Np-N_dela*Lp)+U_1*(L_delr*Np-N_delr*Lp)
DB = g*cos(theta1)*(N_dela*Lr-L_dela*Nr)+g*cos(theta1)*(N_delr*Lr-L_delr*Nr)
N_B = [AB BB CB DB]
%Transfer Function
sys = tf(N_B,D_2)
damp(sys)
Accepted Answer
More Answers (0)
Categories
Find more on Constant-Q, Data-Adaptive, and Quadratic Time-Frequency Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

