Main Content

Batch Compute Steady-State Operating Points Reusing GeneratedMATLABCode

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 theSteady State ManagerorModel 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:

After computing an operating point, generate a MATLAB script. To do so in the:

  • InSteady State Manager, on theSpecificationtab, clickTrim, and selectScript.

  • InLinear Analysis, in the Trim the model dialog box, clickGenerate MATLAB Script.

For more information on generating scripts, seeGenerate 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 themagball金宝app®model.

  1. Open the model.

    open_system('magball')
  2. To open theSteady State Manager, in the Simulink model window, in theAppsgallery, clickSteady State Manager.

  3. On theSteady Statetab, clickTrim Specification.

  4. In thespec1document, in theKnowncolumn, select themagball/Magnetic Ball Plant/heightstate.

  5. Generate the trimming MATLAB code. On theSpecificationtab, clickTrim, and selectScript.

  6. In the MATLAB Editor window, modify the script to trim the model at multiple operating points.

    1. Remove unneeded comments from the generated script.

    2. Define the height variable,height, with values at which to compute operating points.

    3. Add aforloop around the operating point search code to compute a steady-state operating point for eachheightvalue. Within the loop, before callingfindop, update the reference ball height, specified by theDesired Heightblock.

    Your script should look similar to the following code.

    %% Specify the model namemodel ='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 optionsopt = findopOptions('DisplayReport','iter');%% Specify ball heights at which to compute operating points身高= [0.05;0.1;0.15];%% Loop over height values to find the corresponding operating pointsfori = 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,opcontains operating points corresponding to each of the specifiedheightvalues.

See Also

Apps

Functions

Related Topics