# Airframe Trim and Linearize

This example shows how to trim and linearize an airframe using Simulink® Control Design™

Designing an autopilot using classical design techniques requires linear models of the airframe pitch dynamics for a number of trimmed flight conditions. MATLAB® can determine the trim conditions and derive linear state-space models directly from the nonlinear Simulink® and Aerospace Blockset™ model. This saves time and helps to validate the model. The functions provided by Simulink Control Design allow you to visualize the behavior of the airframe in terms of open-loop frequency (or time) responses.

### Initialize Guidance Model

The first problem is to find the elevator deflection, and the resulting trimmed body rate (q), which will generate a given incidence value when the missile is travelling at a set speed. Once the trim condition is found, a linear model can be derived for the dynamics of the perturbations in the states around the trim condition.

```open_system('aero_guidance_airframe'); ``` ### Define State Values

```h_ini = 10000/m2ft; % Trim Height [m] M_ini = 3; % Trim Mach Number alpha_ini = -10*d2r; % Trim Incidence [rad] theta_ini = 0*d2r; % Trim Flightpath Angle [rad] v_ini = M_ini*(340+(295-340)*h_ini/11000); % Total Velocity [m/s] q_ini = 0; % Initial pitch Body Rate [rad/sec] ```

### Set Operating Point and State Specifications

The first state specifications are Position states, the second state specification is Theta. Both are known, but not at steady state. The third state specifications are body axis angular rates of which the variable w is at steady state.

```opspec = operspec('aero_guidance_airframe'); opspec.State(1).Known = [1;1]; opspec.State(1).SteadyState = [0;0]; opspec.State(2).Known = 1; opspec.State(2).SteadyState = 0; opspec.State(3).Known = [1 1]; opspec.State(3).SteadyState = [0 1]; ```

### Search for Operating Point, Set I/O, then Linearize

```op = findop('aero_guidance_airframe',opspec); io(1) = linio('aero_guidance_airframe/Fin Deflection',1,'input'); io(2) = linio('aero_guidance_airframe/Selector',1,'output'); io(3) = linio(sprintf(['aero_guidance_airframe/Aerodynamics &\n', ... 'Equations of Motion']),3,'output'); sys = linearize('aero_guidance_airframe',op,io); ```
``` Operating point search report: --------------------------------- Operating point search report for the Model aero_guidance_airframe. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------- (1.) aero_guidance_airframe/Aerodynamics & Equations of Motion/ Equations of Motion (Body Axes)/Position x: 0 dx: 968 x: -3.05e+03 dx: -171 (2.) aero_guidance_airframe/Aerodynamics & Equations of Motion/ Equations of Motion (Body Axes)/Theta x: 0 dx: -0.216 (3.) aero_guidance_airframe/Aerodynamics & Equations of Motion/ Equations of Motion (Body Axes)/U,w x: 968 dx: -14.1 x: -171 dx: -7.44e-08 (0) (4.) aero_guidance_airframe/Aerodynamics & Equations of Motion/ Equations of Motion (Body Axes)/q x: -0.216 dx: 3.36e-08 (0) Inputs: ---------- (1.) aero_guidance_airframe/Fin Deflection u: 0.136 [-Inf Inf] Outputs: ---------- (1.) aero_guidance_airframe/q y: -0.216 [-Inf Inf] (2.) aero_guidance_airframe/az y: 199 [-Inf Inf] ```

### Select Trimmed States, Create LTI Object, and Plot Bode Response

```airframe = ss(sys.A(3:4,3:4),sys.B(3:4,:),sys.C(:,3:4),sys.D); set(airframe,'inputname',{'Elevator'}, ... 'outputname',[{'az'} {'q'}]); ltiview('bode',airframe); bdclose('aero_guidance_airframe'); ```  