MATLAB Examples

Batch Trim Model for Parameter Variations

This example shows how to obtain multiple operating points for a model by varying parameter values. You can study the controller robustness to plant variations by batch linearizing the model using the trimmed operating points.

Open the Simulink model.

sys = 'watertank';
open_system(sys)

Vary parameters A and b within 10% of their nominal values. Specify three values for A and four values for b, creating a 3-by-4 value grid for each parameter.

[A_grid,b_grid] = ndgrid(linspace(0.9*A,1.1*A,3),...
                         linspace(0.9*b,1.1*b,4));

Create a parameter structure array, specifying the name and grid points for each parameter.

params(1).Name = 'A';
params(1).Value = A_grid;
params(2).Name = 'b';
params(2).Value = b_grid;

Create a default operating point specification for the model, which specifies that both model states are unknown and must be at steady state in the trimmed operating point.

opspec = operspec(sys)
 Operating point specification for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator
	 spec:  dx = 0,  initial guess: 0
(2.) watertank/Water-Tank System/H
	 spec:  dx = 0,  initial guess: 1

Inputs: None 
----------

Outputs: None 
----------


By default, findop displays an operating point search report in the Command Window for each trimming operation. To suppress the report display, create a trimming option set and turn off the operating point search report display.

opt = findopOptions('DisplayReport','off');

Trim the model using the specified operating point specification, parameter grid, and option set.

[op,opreport] = findop(sys,opspec,params,opt);

findop trims the model for each parameter combination. The software uses only one model compilation. op is a 3-by-4 array of operating point objects that correspond to the specified parameter grid points.

View the operating point in the first row and first column of op.

op(1,1)
 Operating point for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator
      x: 1.41         
(2.) watertank/Water-Tank System/H
      x: 10           

Inputs: None 
----------