Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aircraft Flight Dynamics Simulator

Cessna 172S Skyhawk — Longitudinal Flight Dynamics

MATLAB Simulink Version Status License Report

A professional-grade MATLAB/Simulink implementation of the linearised longitudinal flight dynamics of the Cessna 172S Skyhawk — Developed as a personal aerospace engineering portfolio project by an Aerospace Engineering student at King Fahd University of Petroleum and Minerals (KFUPM).

The simulator implements the complete longitudinal analysis pipeline from first principles — no Optimization Toolbox, no Control System Toolbox — using only base MATLAB and Simulink.


Project Preview

Aerodynamic Polars Eigenvalue Poles Step Response – Pitch
Aerodynamic Polars Eigenvalue Pole Map Elevator Step Response (Pitch)
Step Response – Velocity Linear vs Nonlinear Simulink Model
Elevator Step Response (Velocity) Linear vs. Nonlinear Comparison Simulink Block Diagram

Results at a Glance

Reference condition: V₀ = 55 m/s, sea level ISA (ρ = 1.225 kg/m³)

Trim State

Quantity Symbol Value Unit
Trim angle of attack α₀ 0.397 deg
Trim elevator deflection δe₀ 3.358 deg
Trim lift coefficient CL₀ 0.3630
Trim drag coefficient CD₀ 0.0329
Lift-to-weight ratio L/W 1.0000
Trim pitching moment Cm 0 (exact)
Thrust required T 988.4 N

Longitudinal Modes

Mode ωn [rad/s] ζ [-] Period [s] T½ [s] HQ Level
Short-period 5.810 0.868 2.178 0.137 MIL-SPEC Level 1
Phugoid 0.2007 0.0753 31.4 45.87 MIL-SPEC Level 1

Both modes are stable. The short-period mode is well-damped (ζ ≈ 0.87) — pitch disturbances decay within ~0.5 s. The phugoid is lightly-damped (ζ ≈ 0.075), producing the characteristic slow speed-altitude exchange with a period of ~31 s.


Mathematical Model

Equations of Motion (Body Axes)

Nonlinear longitudinal EOM in body-fixed axes:

u̇ = −q·w + (X_aero + T)/m  − g·sin θ
ẇ =  q·u +  Z_aero/m        + g·cos θ
q̇ = M_aero / Iyy
θ̇ = q

Small-Perturbation Linearisation

State vector: x = [Δu Δw Δq Δθ]ᵀ

ẋ = A·x + B·u_ctrl
y  = C·x

A Matrix (dimensional stability derivatives)

        Δu          Δw           Δq            Δθ
Δu̇  [ Xu/m        Xw/m         0          −g·cos θ₀ ]
Δẇ  [ Zu/m        Zw/m         Zq/m + V₀  −g·sin θ₀ ]
Δq̇  [ Mu*/Iyy    Mw*/Iyy      Mq*/Iyy      0        ]
Δθ̇  [  0           0            1            0       ]

Starred derivatives (Mu*, Mw*, Mq*) absorb the Mα̇·ẇ/V₀ coupling term analytically (Nelson 1998, §4.4).

Computed A matrix at trim (V₀ = 55 m/s, α₀ = 0.397°):

        Δu        Δw         Δq         Δθ
Δu̇  [ -0.0324    0.1071    0.0000    -9.8064 ]
Δẇ  [ -0.3566   -2.1972   53.5689    -0.0680 ]
Δq̇  [  0.0134   -0.3063   -7.8881     0.0000 ]
Δθ̇  [  0.0000    0.0000    1.0000     0.0000 ]

Project Architecture

Project Architecture

The pipeline runs from a single parameter source through trim, state-space assembly, modal analysis, and simulation to validated engineering outputs. Each module is self-contained and unit-testable.


MATLAB Workflow

MATLAB Workflow

Running main.m orchestrates all six stages in sequence. Each canonical module accepts structured inputs and returns structured outputs — no global state.


Simulink Cross-Validation

Simulink Model

A programmatic Simulink state-space block is built from the same A, B, C, D matrices produced by the MATLAB pipeline, providing an independent cross-validation path.

Check Simulink Workflow
Model construction build_simulink_model.m builds C172_Longitudinal_SS.slx programmatically
State-space source Same A, B, C, D from build_state_space.m
Cross-validation run_simulink_comparison.m prints MATLAB vs Simulink error table
Toolbox required Simulink only (no Control System Toolbox)

Repository Highlights

Feature Implementation
No-toolbox trim solver Exact 2×2 linear system (MATLAB \ operator) — no fsolve, no Optimization Toolbox
No-toolbox simulation ode45 directly on ẋ = Ax + Bu with two-phase split — no lsim, no Control System Toolbox
Starred moment derivatives Mα̇ coupling absorbed analytically before A-matrix assembly (Nelson 1998 §4.4)
Two-phase ODE integration Step discontinuity handled by splitting integration at t_step — avoids event-detection overhead
Simulink cross-validation Programmatic model built from same matrices — independent validation path
Quantitative validation Trim residuals, MIL-SPEC-8785C Level 1 check, Lanchester approximation comparison
Engineering report 10-section PDF report compiled from Markdown via Pandoc + XeLaTeX
Single parameter source aircraft_parameters.m is the sole source of truth — no magic numbers anywhere else

Repository Structure

Repository Structure

Aircraft-Flight-Dynamics-Simulator/
│
├── matlab/                     MATLAB source code (13 modules)
│   ├── main.m                      Orchestrator — run this file
│   ├── aircraft_parameters.m       Single parameter source of truth
│   ├── compute_derived_params.m    Derived quantities (W, AR, q_bar, CL_trim)
│   ├── aero_forces.m               Aerodynamic coefficients at any state
│   ├── compute_trim.m              Trim solver — exact 2×2 linear system
│   ├── build_state_space.m         A, B, C, D matrix assembly
│   ├── eom_longitudinal.m          Nonlinear body-axis EOM for ode45
│   ├── analyze_modes.m             Eigenvalue → SP and phugoid extraction
│   ├── simulate_response.m         Linear + nonlinear ode45 integration
│   ├── plot_results.m              Five engineering figures → figures/
│   ├── validate_model.m            Quantitative validation report
│   └── [5 backward-compatibility wrappers]
│
├── simulink/                   Simulink cross-validation
│   ├── build_simulink_model.m      Builds C172_Longitudinal_SS.slx
│   ├── run_simulink_comparison.m   MATLAB vs Simulink error table
│   └── C172_Longitudinal_SS.slx   [generated — run build_simulink_model.m]
│
├── reports/                    Engineering documentation
│   ├── Engineering_Report.pdf      10-section technical report (PDF)
│   └── Engineering_Report_PDFReady.md   Pandoc + XeLaTeX source
│
├── docs/                       Technical reference documentation
│   ├── Model_Reference.md          Equations, module pipeline, assumptions
│   ├── State_Space_Model.md        A, B, C, D matrix derivation
│   └── State_Variables.md          State vector definitions and sign conventions
│
├── references/                 Aircraft data (Nelson 1998 Appendix B)
├── figures/                    Generated PNG figures (auto-populated by main.m)
├── README.md
├── RELEASES.md
├── .gitignore
└── .gitattributes

Installation & Requirements

Requirements

Requirement Version Notes
MATLAB R2019b or later Base MATLAB only
Simulink R2019b or later Required only for simulink/ scripts
Optimization Toolbox Not required
Control System Toolbox Not required
Signal Processing Toolbox Not required

Quick Start

% 1. Clone the repository
%    git clone https://github.com/yourusername/Aircraft-Flight-Dynamics-Simulator.git

% 2. In MATLAB, navigate to the matlab/ folder:
cd('path/to/Aircraft-Flight-Dynamics-Simulator/matlab')

% 3. Run the full longitudinal analysis pipeline:
main

This executes all six pipeline stages and opens five engineering figures:

  1. Aerodynamic polars (lift curve, drag polar, L/D ratio)
  2. Eigenvalue pole map with constant-damping lines
  3. Step response — elevator command, pitch angle, pitch rate
  4. Step response — forward velocity and angle of attack
  5. Linear vs. nonlinear comparison (all four states)

Figures are saved as PNG files to the figures/ directory at 300 dpi.

Validation Report

cd('path/to/Aircraft-Flight-Dynamics-Simulator/matlab')
validate_model

Prints trim residuals, aerodynamic polar consistency, Lanchester approximation comparison, and MIL-SPEC-8785C Level 1 handling quality assessment.

Simulink Model

cd('path/to/Aircraft-Flight-Dynamics-Simulator/simulink')
build_simulink_model       % creates C172_Longitudinal_SS.slx
run_simulink_comparison    % prints MATLAB vs Simulink error table

Validation Summary

Check Criterion Result Status
Trim: L/W residual < 1e-10 5.5e-15 PASS
Trim: Cm residual < 1e-10 2.2e-16 PASS
Trim CL > 0 Physical 0.3630 PASS
Trim CD > 0 Physical 0.0329 PASS
Elevator δe₀ in bounds |δe| < 25° 3.36° PASS
SP: ωn (MIL-SPEC Level 1) ≥ 1.0 rad/s 5.810 rad/s PASS
SP: ζ (MIL-SPEC Level 1) 0.35 ≤ ζ ≤ 1.30 0.868 PASS
SP: time to half amplitude < 1 s (Level 1) 0.137 s PASS
PH: ζ (MIL-SPEC Level 1) ≥ 0.04 0.0753 PASS
PH: stability ζ > 0 0.0753 PASS
Lanchester ωn approx. Within ~20% expected 0.252 vs 0.201 rad/s Expected
System stability All eigenvalues LHP 4/4 LHP PASS

Aircraft Data

All aerodynamic and stability data sourced from: R. C. Nelson, "Flight Stability and Automatic Control," 2nd ed., McGraw-Hill, 1998, Appendix B — Cessna 172 (modified).

Geometric & Inertial Properties

Parameter Symbol Value Unit
Wing area S 16.2
Wing span b 11.0 m
Mean aerodynamic chord 1.494 m
Aspect ratio AR 7.47
Mass (gross weight) m 1111 kg
Pitch moment of inertia Iyy 1285.3 kg·m²

Aerodynamic Coefficients

Parameter Symbol Value Unit
Lift-curve slope CL_α 4.44 /rad
Zero-lift drag CD0 0.0270
Induced drag factor k 0.0450
Static stability Cm_α −0.613 /rad
Pitch damping Cm_q −12.40 /rad
Elevator effectiveness Cm_δe −1.122 /rad

Static margin: 13.8% MAC (statically stable).


Key Engineering Decisions

Trim solver — no Optimization Toolbox:
The aerodynamic model is linear in α and δe, so the two trim conditions (CL = CL_req and Cm = 0) form an exact 2×2 linear system. Solved with MATLAB's backslash operator — no fsolve, no optimoptions.

Simulation — no Control System Toolbox:
Uses ode45 directly on ẋ = Ax + Bu with two-phase integration split at the step discontinuity (t_step), instead of lsim. This guarantees correct input values on both sides of the discontinuity and avoids any dependency on the Control System Toolbox.

Starred moment derivatives:
The Mα̇ coupling term is absorbed analytically into starred derivatives (Mw*, Mq*, Mde*) before building the A matrix, following Nelson 1998, §4.4. This keeps the A matrix in standard 4×4 form without an augmented state.

Two-phase ODE integration:
The elevator step response is integrated in two sequential ode45 calls — one before the step and one after — with initial conditions for the second phase taken from the final state of the first. This avoids numerical artefacts at the discontinuity.

Single parameter source:
All aircraft constants are defined once in aircraft_parameters.m. No module contains hard-coded numerical values. Changing an aircraft parameter propagates automatically through the entire pipeline.


References

  1. R. C. Nelson, Flight Stability and Automatic Control, 2nd ed., McGraw-Hill, 1998.
  2. B. L. Stevens, F. L. Lewis, E. N. Johnson, Aircraft Control and Simulation, 3rd ed., Wiley, 2016.
  3. B. Etkin and L. D. Reid, Dynamics of Flight: Stability and Control, 3rd ed., Wiley, 1996.
  4. U.S. Department of Defense, MIL-SPEC-8785C: Flying Qualities of Piloted Airplanes, 1980.
  5. Cessna Aircraft Company, Cessna 172S Pilot's Operating Handbook, 2009.

Future Work

Version 2 Roadmap

  • Lateral-directional dynamics — roll, yaw, sideslip modes (Dutch roll, spiral, roll subsidence)
  • Coupled 6-DOF simulation — full nonlinear equations of motion
  • PID autopilot design — pitch hold, altitude hold, airspeed hold
  • Gust and turbulence response — Dryden turbulence model
  • Multiple flight conditions — envelope analysis at different speeds and altitudes

Version 1 Complete

  • Aircraft parameter database
  • Aerodynamic model (CL, CD, Cm, CX, CZ)
  • Trim analysis (exact 2×2 linear solve — no toolbox)
  • Linearised state-space model (A, B, C, D)
  • Longitudinal modal analysis (short-period and phugoid)
  • Nonlinear EOM simulation (ode45)
  • Engineering figures (5 figures, 300 dpi PNG)
  • Simulink state-space model (cross-validation)
  • Quantitative validation report (MIL-SPEC-8785C)
  • 10-section engineering report (PDF via Pandoc + XeLaTeX)

License

This project is licensed under the MIT License. See LICENSE for details.


Acknowledgements

  • R. C. Nelson — the textbook that defines this course of study; the Cessna 172S aerodynamic dataset is from Appendix B.
  • KFUPM Aerospace Engineering Department — for the academic foundation that made this project possible.
  • MathWorks — for MATLAB and Simulink documentation and examples.

Author

Osama AlFadel
Aerospace Engineering Student
King Fahd University of Petroleum and Minerals (KFUPM)

About

Professional MATLAB/Simulink implementation of the longitudinal flight dynamics of the Cessna 172S Skyhawk.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages