This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

More Efficient Batch Linearization Varying Parameters

This example shows how to use the command LINEARIZE to speed up the batch linearization where a set of block parameters are varied.


This example shows how to use the command LINEARIZE to speed up the batch linearization where a set of block parameters are varied. The speed up is achieved by passing the varying parameters to LINEARIZE. LINEARIZE avoids recompiling the model when varying these parameters if they are tunable parameters. The best improvements in the overall linearization time are for models with large model update times. To run this example, you need Aerospace Blockset.

Linearizing the Full Simulink Model 20 Times Calling LINEARIZE in a FOR Loop

In this example, you linearize a model of a lightweight airplane while varying the gain of the altitude and pitch controllers by +/- 10%. Open the Simulink model for lightweight airplane. You can find more information on this model in the example "Lightweight Airplane Design" in Aerospace Blockset examples.

mdl = 'scdskyhogg';
io = getlinio(mdl);
op = operpoint(mdl);

Initialize the gain of the controllers to vary with MATLAB workspace parameters k1 and k2:

open_system('scdskyhogg/Vehicle System Model/Avionics/Autopilot')
blks = {'scdskyhogg/Vehicle System Model/Avionics/Autopilot/Alt Controller';...
        'scdskyhogg/Vehicle System Model/Avionics/Autopilot/Theta Controller'};

Compute 20 linearizations:

t = cputime;
for ct = 20:-1:1
    k1 = 1+(ct-10)/100;
    k2 = 1+(ct-10)/100;
    sys_forloop(:,:,ct) = linearize(mdl,op,io);

View the total time to compute the 20 linearizations in seconds:

dt_for = cputime - t
dt_for =


A factor that impacts this time is the total time it takes to compile and evaluate block masks and resolve workspace parameters. The MATLAB Profiler is a recommended tool that you can use to identify bottlenecks in this compilation process.

Linearizing the Simulink Model 20 Times Specifying Parameters to LINEARIZE

We vary only the two parameters. You can use the LINEARIZE command syntax where the parameter names and values are passed using a structure:

ct = 1:20;
k1val = 1+(ct-10)/100;
k2val = 1+(ct-10)/100;

params(1).Name = 'k1';
params(1).Value = k1val;
params(2).Name = 'k2';
params(2).Value = k2val;

t = cputime;
sys_params = linearize(mdl,op,io,params);

View the total time to compute the 20 linearizations with one call to LINEARIZE command. Note that the model is compiled only once when varying the specified parameters.

dt_params = cputime - t
dt_params =


Comparing the Results

In this example, the parameters varied do not have any impact on the operating point of the Simulink model. The linearizations using both approaches are equivalent.

legend('Linearization in a FOR loop','Linearization using parameter structure')

Calculate the resulting time improvement ratio:

ratio = dt_for/dt_params
ratio =


Close the Simulink model