Batch Compute Steady-State Operating Points Reusing Generated MATLAB Code
This example shows how to batch-compute steady-state operating points for a model using generated MATLAB® code. You can either simulate or linearize your model at these operating points and study the change in model behavior.
If you are new to writing scripts, interactively configure your operating points search using the Steady State Manager or Model Linearizer.
Before generating code for batch trimming, first compute an operating point to meet an instance of your specifications. For more information on computing operating points in:
Steady State Manager, see Compute Operating Points from Specifications Using Steady State Manager.
Model Linearizer, see Compute Operating Points from Specifications Using Model Linearizer.
After computing an operating point, generate a MATLAB script. To do so in the:
In Steady State Manager, on the Specification tab, click Trim , and select
Script
.In Linear Analysis, in the Trim the model dialog box, click Generate MATLAB Script.
For more information on generating scripts, see Generate MATLAB Code for Operating Point Configuration.
The generated script opens in the MATLAB Editor window. You can then modify the script to trim the model at multiple operating points.
This example demonstrates batch trimming using the magball
Simulink® model.
Open the model.
openExample("magball")
To open the Steady State Manager, in the Simulink model window, in the Apps gallery, click Steady State Manager.
On the Steady State tab, click Trim Specification.
In the spec1 document, in the Known column, select the magball/Magnetic Ball Plant/height state.
Generate the trimming MATLAB code. On the Specification tab, click Trim , and select
Script
.In the MATLAB Editor window, modify the script to trim the model at multiple operating points.
Remove unneeded comments from the generated script.
Define the height variable,
height
, with values at which to compute operating points.Add a
for
loop around the operating point search code to compute a steady-state operating point for eachheight
value. Within the loop, before callingfindop
, update the reference ball height, specified by the Desired Height block.
Your script should look similar to the following code.
%% Specify the model name model = 'magball'; %% Create the operating point specification object. opspec = operspec(model); %% Set the constraints on the states in the 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 specifiedheight
values.
See Also
Apps
Functions
Related Topics
- Generate MATLAB Code for Operating Point Configuration
- Batch Linearize Model at Multiple Operating Points Using linearize Command
- Vary Operating Points and Obtain Multiple Transfer Functions Using slLinearizer Interface
- Batch Compute Steady-State Operating Points for Multiple Specifications
- Batch Compute Steady-State Operating Points for Parameter Variation