I need help constructing a more efficient code to plot multiple data points on one step plot

15 views (last 30 days)
I am working on an assignment for my Stability and Control class that is pretty extensive as far as lines of code are concerned. We are to code flight dynamics for a Cessna 182 aircraft in which we are analyzing the flight affects of things such as:
  • AoA/Pitch due to elevator deflection
  • Slide slip due to aileron/rudder deflection
  • Heading due to aileron/rudder deflection
We are analyzing the short period, phugoid, dutch roll, roll, short period approximation, phugoid approximation, Dutch roll approximation, and roll approximations transfer functions for the aircraft in 3 different flight conditions; Climb, Cruise, and Approach. We are given the aircrafts specific data, longitudinal, and lateral-directional variables.
I have already created the code for each aformentioned condition but they are in separate .m files. What I would ultimately like to happen is have a single file or a couple of files (longitudinal and lateral-directional) that can model these dynamics and output a step(sys) plot that overlays the first 3 seconds of the dynamics (t = 0:0.01:3) for each analysis with its associated approximation e.g. AoA to elevator deflection for climb, cruise, and approach short period dynamics and short period approximation for climb, cruise, and approach -- 6 trends on one plot.
I am adding the code for just the AoA to elevator deflection and approximation for all three flight conditions to this query to see if someone is able to find a solution that is more efficient than having separate files. I am not MATLAB savvy enough to create a more truncated solution yet.
  4 Comments
Jeffrey Lewis
Jeffrey Lewis on 22 Nov 2022
Yes, by "more efficient", I mean I would like to reduce the number of lines of code to produce the same outcome. You have already presented a couple of good ideas for reduction.
All of the files I added are part of the longitudinal dynamics analysis. I have 11 more .m files for this portion and 36 .m files for lateral-directional dynamics. All of the parameters for Longitudinal Dynamics are the same in each file (with flight condition variables called accordingly). The same goes for all of the Lateral-Directional Dynamics files. The only code that changes between all of them are the numerator/Denominator polynomial lines which will utilize the existing parameters (as you saw).
My goal is to put all Logitudinal Dynamics analysis conditions into one file and Lateral-Directional analysis into another file and within each of those files, be able to either model the dynamics iteratively, have the code request a condition to analyze, or be able to build a simulink model that can model the dynamics accordingly.
In my head, it makes sense to have all data in one Longitudinal Dynamics file, for instance, and have the code run AoA due to Elevator Deflection parameters, then Pitch due to Elevator Deflection, and then on to the approximation dynamics, etc. The issue I see with this is when the subsequent dynamics are modeled, the previous dynamics will be overwritten.
Thank you for the feedback you have given thus far, Brian!
@Paul I like this idea of possibly adding all of the flight conditions as an array and storing the transfer functions using the Model Array function. How would Model Arrays execute when modeling the dynamics? I looked on the Model Arrays page to see how the syntax would look. Do I capture the numerator and denominator polynomials as I have already done but just setup the transfer functions as:
sys1 = tf(N,D)
sys2 = tf(N,D)
sys3 = tf(N,D)
sysn = tf(N,D)
When I use the step(sysArray) function, will this model all transfer functions stored?
Should the array for all flight conditions look like this [below]? And thank you as well, Paul, for your feedback!
%Climb, Cruise, Approach conditions
h = [0 5000 0] %Altitude (ft)
M = [0.120 0.201 0.096] %Mach Number
U_1 = [133.5 220.1 107.1 %TAS (ft/s)
q = [21.2 49.6 13.6] %Dynamic Pressure (lbs/ft^2)
c_frac = 26.4 %CG Location
a_1 = [5.4 0 4]%Angle of Attack (Deg)
Paul
Paul on 22 Nov 2022
Edited: Paul on 22 Nov 2022
If using a model array, each model is stored as one element of the array. The model array itself can be multi-dimensional if it makes sense to do so. Here's a simple example.
sys1 = tf(1,[1 1],'Name','pitch');
sys2 = tf(1,[2 1],'Name','yaw');
sys = stack(1,sys1,sys2);
step(sys),legend
Actually, now that I think of it one of the drawbacks of Model Arrays is shown above, i.e., it's not easy to distinguish which curve on the plot goes with which model. Maybe it's easier to do
step(sys1,sys2),legend

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!