MATLAB Examples

# Batch Trim Model at Known States Derived from Parameter Values

This example shows how to batch trim a model when the specified parameter variations affect the known states for trimming.

In the docid:slcontrol_ug.bvfqv1l example, the model is trimmed to meet a single operating point specification that contains unknown states. In other cases, the model states are known for trimming, but depend on the values of the varying parameters. In this case, you cannot batch trim the model using a single operating point specification. You must create a separate specification for each parameter value grid point.

sys = 'scdairframeTRIM'; open_system(sys) 

In this model, the aerodynamic forces and moments depend on the speed, , and incidence, .

Vary the and parameters, and create a 6-by-4 parameter grid.

nA = 6; % number of alpha values nV = 4; % number of V values alphaRange = linspace(-20,20,nA)*pi/180; vRange = linspace(700,1400,nV); [alphaGrid,vGrid] = ndgrid(alphaRange,vRange); 

Since some known state values for trimming depend on the values of and , you must create a separate operating point specification object for each parameter combination.

for i = 1:nA for j = 1:nV % Set parameter values in model. alpha_ini = alphaGrid(i,j); v_ini = vGrid(i,j); % Create default specifications based on the specified parameters. opspec(i,j) = operspec(sys); % Specify which states are known and which states are at steady state. opspec(i,j).States(1).Known = [1;1]; opspec(i,j).States(1).SteadyState = [0;0]; opspec(i,j).States(3).Known = [1;1]; opspec(i,j).States(3).SteadyState = [0;1]; opspec(i,j).States(2).Known = 1; opspec(i,j).States(2).SteadyState = 0; opspec(i,j).States(4).Known = 0; opspec(i,j).States(4).SteadyState = 1; end end 

Create a parameter structure for batch trimming. Specify a name and value grid for each parameter.

params(1).Name = 'alpha_ini'; params(1).Value = alphaGrid; params(2).Name = 'v_ini'; params(2).Value = vGrid; 

Trim the model using the specified parameter grid and operating point specifications. When you specify an array of operating point specifications and varying parameter values, the dimensions of the specification array must match the parameter grid dimensions.

opt = findopOptions('DisplayReport','off'); op = findop(sys,opspec,params,opt); 

findop trims the model for each parameter combination. op is a 6-by-4 array of operating point objects that correspond to the specified parameter grid points.