Main Content

findop

Steady-state operating point from specifications (trimming) or simulation

描述

example

op= findop(mdl,opspec)returns the operating point of the model that meets the specifications inopspec. Typically, you trim the model at asteady-state operating point. The Simulink®model must be open. Ifopspecis an array of operating points specifications,findopreturns an array of corresponding operating points.

example

op= findop(mdl,opspec,param)batch trims the model for the parameter value variations specified inparam.

example

op= findop(___,options)trims the model using additional optimization algorithmoptions.

example

[op,opreport] = findop(___)returns an operating point search report,opreport, for any of the previous syntaxes.

example

op= findop(mdl,tsnapshot)simulates the model using the model initial conditions, and extracts operating points at simulation snapshot times specified intsnapshot.

example

op= findop(mdl,tsnapshot,param)batch simulates the model using the parameter value variations specified inparam.and extracts operating points at simulation snapshot times.

Examples

collapse all

Open the Simulink model.

mdl ='watertank'; open_system(mdl)

Trim the model to find a steady-state operating point where the water tank level is10.

Create default operating point specification object.

opspec = operspec(mdl);

Configure specifications for the first model state. The first state must be at steady state with a lower bound of0. Provide an initial guess of2for the state value.

opspec.States(1).SteadyState = 1; opspec.States(1).x = 2; opspec.States(1).Min = 0;

Configure the second model state as a known state with a value of10.

opspec.States(2).Known = 1; opspec.States(2).x = 10;

Find the operating point that meets these specifications.

op = findop(mdl,opspec);
Operating point search report: --------------------------------- opreport = Operating point search report for the Model watertank. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------- Min x Max dxMin dx dxMax ______ ______ ______ ______ ______ ______ (1.) watertank/PID Controller/Integrator/Continuous/Integrator 0 1.2649 Inf 0 0 0 (2.) watertank/Water-Tank System/H 10 10 10 0 0 0 Inputs: None ---------- Outputs: None ----------

Open the Simulink model.

mdl ='watertank'; open_system(mdl)

Vary parametersAandbwithin 10% of their nominal values, and create a 3-by-4 parameter grid.

[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.

opspec = operspec(mdl);

削减模型使用指定的操作点specification and parameter grid.

opt = findopOptions('DisplayReport','off'); op = findop(mdl,opspec,params,opt);

opis a 3-by-4 array of operating point objects that correspond to the specified parameter grid points.

Open the Simulink model.

mdl ='watertank'; open_system(mdl)

Create a default operating point specification object.

opspec = operspec(mdl);

Create an option set that sets the optimizer type to gradient descent and suppresses the search report display.

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

Trim the model using the specified option set.

op = findop(mdl,opspec,opt);

Open the Simulink model.

mdl ='watertank'; open_system(mdl)

Create default operating point specification object.

opspec = operspec(mdl);

Configure specifications for the first model state.

opspec.States(1).SteadyState = 1; opspec.States(1).x = 2; opspec.States(1).Min = 0;

Configure specifications for the second model state.

opspec.States(2).Known = 1; opspec.States(2).x = 10;

Find the operating point that meets these specifications, and return the operating point search report. Create an option set to suppress the search report display.

opt = findopOptions('DisplayReport',false); [op,opreport] = findop(mdl,opspec,opt);

opreportdescribes how closely the optimization algorithm met the specifications at the end of the operating point search.

opreport
opreport = Operating point search report for the Model watertank. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------- Min x Max dxMin dx dxMax ______ ______ ______ ______ ______ ______ (1.) watertank/PID Controller/Integrator/Continuous/Integrator 0 1.2649 Inf 0 0 0 (2.) watertank/Water-Tank System/H 10 10 10 0 0 0 Inputs: None ---------- Outputs: None ----------

dxis the time derivative for each state. Since alldxvalues are zero, the operating point is at steady state.

Open the Simulink model.

mdl ='magball'; open_system(mdl)

Simulate the model, and extract operating points at10and20time units.

op = findop(mdl,[10,20]);

opis a column vector of operating points, with one element for each snapshot time.

Display the first operating point.

op(1)
ans = Operating point for the Model magball. (Time-Varying Components Evaluated at time t=10) States: ---------- x __________ (1.) magball/Controller/PID Controller/Filter/Cont. Filter/Filter 5.4732e-07 (2.) magball/Controller/PID Controller/Integrator/Continuous/Integrator 14.0071 (3.) magball/Magnetic Ball Plant/Current 7.0036 (4.) magball/Magnetic Ball Plant/dhdt 8.443e-08 (5.) magball/Magnetic Ball Plant/height 0.05 Inputs: None ----------

Open Simulink model.

mdl ='watertank'; open_system(mdl)

Specify parameter values. The parameter grids are 5-by-4 arrays.

[A_grid,b_grid] = ndgrid(linspace(0.9*A,1.1*A,5),...linspace(0.9*b,1.1*b,4)); params(1).Name ='A'; params(1).Value = A_grid; params(2).Name ='b'; params(2).Value = b_grid;

Simulate the model and extract operating points at0,5, and10time units.

op = findop(mdl,[0 5 10],params);

findopsimulates the model for each parameter value combination, and extracts operating points at the specified simulation times.

opis a 3-by-5-by-4 array of operating point objects.

size(op)
ans = 3 5 4

Input Arguments

collapse all

Simulink model name, specified as a character vector or string. The model must be in the current working folder or on the MATLAB®path.

Operating point specifications for trimming the model, specified as anOperatingSpecobject or an array ofOperatingSpec对象created using theoperspecfunction.

Ifopspecis an array,findopreturns an array of corresponding operating points using a single model compilation.

Parameter samples for trimming, specified as one of the following:

  • Structure — Vary the value of a single parameter by specifyingparam作为一个方法e with the following fields:

    • Name— Parameter name, specified as a character vector or string. You can specify any model parameter that is a variable in the model workspace, the MATLAB workspace, or a data dictionary. If the variable used by the model is not a scalar variable, specify the parameter name as an expression that resolves to a numeric scalar value. For example, to use the first element of vectorVas a parameter, use:

      param.Name ='V(1)';
    • Value— Parameter sample values, specified as a double array.

    For example, vary the value of parameterAin the 10% range:

    param.Name ='A'; param.Value = linspace(0.9*A,1.1*A,3);
  • Structure array — Vary the value of multiple parameters. For example, vary the values of parametersAandbin the 10% range:

    [A_grid,b_grid] = ndgrid(linspace(0.9*A,1.1*A,3),...linspace(0.9*b,1.1*b,3)); params(1).Name ='A'; params(1).Value = A_grid; params(2).Name ='b'; params(2).Value = b_grid;

When you specify parameter value variations,findopbatch trims the model for each parameter value combination, and returns an array of corresponding operating points. Ifparamspecifies tunable parameters only, then the software batch trims the model using a single compilation.

If you specifyopspecas a singleoperspecobject and the parameter values inparamproduce states that conflict with known states inopspec,findoptrims the model using the specifications inopspec. To trim the model at state values derived from the parameter values, specifyopspecas an array of correspondingoperspec对象. For an example, seeBatch Trim Simulink Model for Parameter Variation.

Trimming options, specified as afindopOptionsoption set.

Simulation snapshot times at which to extract the operating point of the model, specified as a scalar for a single snapshot or a vector for multiple snapshots.findopsimulates the model and computes an operating point for the state of the model at each snapshot time.

Output Arguments

collapse all

Operating point, returned as anOperatingPointobject or an array ofOperatingPoint对象. The dimensions ofopdepend on the specified parameter variations and either the operating-point specifications or the simulation snapshot time.

Parameter Variation Find operating point for... ResultingopDimensions
No parameter variation Single operating-point specification, specified byopspec single operating-point object
Single snapshot time, specified bytsnapshot
N1-by-...-by-Nmarray of operating-point specifications, specified byopspec N1-by-...-by-Nm
Nssnapshots, specified bytsnapshot Column vector of lengthNs
N1-by-...-by-Nmparameter grid, specified byparam Single operating-point specification, specified byopspec N1-by-...-by-Nm
Single snapshot time, specified bytsnapshot
N1-by-...-by-Nmarray of operating-point specifications, specified byopspec
Nssnapshots, specified bytsnapshot Ns-by-N1-by-...-by-Nm.

For example, suppose:

  • opspecis a single operating-point specification object andparamspecifies a 3-by-4-by-2 parameter grid. In this case,opis a 3-by-4-by-2 array of operating points.

  • tsnapshotis a scalar andparamspecifies a 5-by-6 parameter grid. In this case,opis a 1-by-5-by-6 array of operating points.

  • tsnapshotis a row vector with three elements andparamspecifies a 5-by-6 parameter grid. In this case,opis a 3-by-5-by-6 array of operating points.

Each operating-point object has the following properties:

Property 描述
Model Simulink model name, returned as a character vector.
States

State operating point, returned as a vector of state objects. Each entry inStatesrepresents the supported states of one Simulink block.

For a list of supported states for operating point objects, seeSimulink Model States Included in Operating Point Object.

Note

If the block has multiple named continuous states,Statescontains one structure for each named state.

Each state object has the following fields:

Field 描述
Nx(read only)

Number of states in the block

Block

Block path, returned as a character vector.

StateName

State name

x

Values of all supported block states, returned as a vector of lengthNx.

Ts

Sample time and offset of each supported block state, returned as a vector. For continuous-time systems,Tsis zero.

SampleType

State time rate, returned as one of the following:

  • 'CSTATE'— Continuous-time state

  • 'DSTATE'— Discrete-time state

inReferencedModel

Flag indicating whether the block is inside a reference model, returned as one of the following:

  • 1— Block is inside a reference model.

  • 0— Block is in the current model file.

描述

Block state description, returned as a character vector.

Inputs

Input level at the operating point, returned as a vector of input objects. Each entry inInputsrepresents the input levels of one root-level inport block in the model.

Each input object has the following fields:

Field 描述
Nu(read only)

Number of inport block signals

Block

Inport block name

PortDimensions

Dimension of signals accepted by the inport

u

Inport block input levels at the operating point, returned as a vector of lengthNu.

描述

Inport block input description, returned as a character vector.

Time

Times at which any time-varying functions in the model are evaluated, returned as a vector.

Version

Object version number

You can edit the properties ofopusing dot notation or thesetfunction.

Operating point search report, returned as anOperatingReportobject. Ifopis an array ofOperatingPoint对象, thenopreportis an array of correspondingOperatingReport对象.

This report displays automatically, even when you suppress the output using a semicolon. To hide the report, set theDisplayReportfield inoptionsto'off'.

Each operating point search report has the following properties:

Property 描述
Model

Modelproperty value ofop

Inputs

Inputsproperty value ofop

Outputs

Output values at the computed operating point. This object contains the same fields as theOutputsproperty ofopspec, with the addition ofyspec, which is the desired output value.

States

Statesproperty value ofopwith the addition ofdx, which contains the state derivative values. For discrete-time states,dx是不同的ence between the next state value and the current one; that is,x(k+1) –x(k).

Time Timeproperty value ofop
TerminationString Optimization termination condition, returned as a character vector.
OptimizationOutput

Optimization algorithm search results, returned as a structure with the following fields:

Field 描述
iterations

Number of iterations performed during the optimization

funcCount

Number of function evaluations performed during the optimization

lssteplength

Size of line search step relative to search direction (active-set optimization algorithm only)

stepsize

Displacement in the state vector at the final iteration (active-set and interior-point optimization algorithms)

algorithm

Optimization algorithm used

firstorderopt

Measure of first-order optimization, for the trust-region-reflective optimization algorithm;[]for other algorithms

constrviolation

Maximum of constraint functions

message

Exit message

For more information about the optimization algorithm, see the Optimization Toolbox™ documentation.

More About

collapse all

Steady-State Operating Point (Trim Condition)

Asteady-state operating point一个模型,也称为一个平衡或trimcondition, includes state variables that do not change with time.

A model can have several steady-state operating points. For example, a hanging damped pendulum has two steady-state operating points at which the pendulum position does not change with time. Astable steady-state operating pointoccurs when a pendulum hangs straight down. When the pendulum position deviates slightly, the pendulum always returns to equilibrium. In other words, small changes in the operating point do not cause the system to leave the region of good approximation around the equilibrium value.

Anunstable steady-state operating pointoccurs when a pendulum points upward. As long as the pendulum pointsexactlyupward, it remains in equilibrium. However, when the pendulum deviates slightly from this position, it swings downward and the operating point leaves the region around the equilibrium value.

When using optimization search to compute operating points for nonlinear systems, your initial guesses for the states and input levels must be near the desired operating point to ensure convergence.

When linearizing a model with multiple steady-state operating points, it is important to have the right operating point. For example, linearizing a pendulum model around the stable steady-state operating point produces a stable linear model, whereas linearizing around the unstable steady-state operating point produces an unstable linear model.

Tips

  • You can initialize an operating point search at a simulation snapshot or a previously computed operating point usinginitopspec.

  • Linearize the model at the operating pointopusinglinearize.

Algorithms

By default,findopuses the optimizergraddescent-elim. To use a different optimizer, change the value ofOptimizerTypeinoptionsusingfindopOptions.

findopautomatically sets these Simulink model properties for optimization:

  • BufferReuse = 'off'

  • RTWInlineParameters = 'on'

  • BlockReductionOpt = 'off'

  • SaveFormat = 'StructureWithTime'

After the optimization completes, Simulink restores the original model properties.

Alternative Functionality

App

As an alternative to thefindopcommand, you can find operating points in one of the following ways.

版本历史

Introduced before R2006a

expand all