This example shows how to batch compute steady-state operating points for a model using generated MATLAB® code. You can batch linearize a model using the operating points and study the change in model behavior.
If you are new to writing scripts, interactively configure your operating points search using the Linear Analysis Tool. You can use Simulink® Control Design™ to automatically generate a script based on your Linear Analysis Tool settings.
Open the Simulink model.
sys = 'magball'; open_system(sys)
In the Simulink Editor, select Analysis > Control Design > Linear Analysis.
In the Linear Analysis Tool, in the Operating
Point drop-down list, click
By default, the software specifies all model states to be at equilibrium, as shown in the Steady State column.
In the States tab, select the Known check box for the magball/Magnetic Ball Plant/height state.
Click Start trimming to compute the operating point using numerical optimization.
The Trim progress viewer shows that the optimization algorithm
terminated successfully. The
(Maximum Error) Block area
shows the progress of reducing the error of a specific state or output
during the optimization.
In the Trim the model dialog box, click Generate MATLAB Script
The MATLAB Editor window opens with an automatically generated script.
Modify the script to trim the model at multiple operating points.
Remove unneeded comments from the generated script.
Define the height variable,
with values at which to compute operating points.
for loop around the operating
point search code to compute a steady-state operating point for each
Within the loop, before calling
the reference ball height, specified by the Desired Height block.
Your script should now look similar to this:
%% Specify the model name model = 'magball'; %% Create the operating point specification object. opspec = operspec(model); % State (5) - magball/Magnetic Ball Plant/height % - Default model initial conditions are used to initialize optimization. opspec.States(5).Known = true; %% Create the options opt = findopOptions('DisplayReport','iter'); %% Specify ball heights at which to compute operating points height = [0.05;0.1;0.15]; %% Loop over height values to find the corresponding operating points for i = 1:length(height) % Set the ball height in the specification opspec.States(5).x = height(i); % Update the model ball haight reference parameter set_param('magball/Desired Height','Value',num2str(height(i))) % Trim the model [op(i),opreport(i)] = findop(model,opspec,opt); end
After running this script,
op contains operating
points corresponding to each of the specified