主要内容

Batch Compute Steady-State Operating Points for Parameter Variation

块参数配置simulink金宝app®model in several ways. For example, you can use block parameters to specify various coefficients or controller sample times. You can also use a discrete parameter, like the control input to a多端口开关block, to control the data path within a model. Varying the value of a parameter helps you understand its impact on the model behavior. Also, you can vary the parameters of a plant model in a control system to study the robustness of the controller to plant variations.

在修剪模型时使用findop,您可以指定一组参数值来修剪模型。完整的值称为parameter grid或者参数samplesfindopcomputes an operating point for each value combination in the parameter grid. You can vary multiple parameters, thus extending the parameter grid dimension.

Which Parameters Can Be Sampled?

You can vary any model parameter with a value given by a variable in the model workspace, the MATLAB®workspace, or a data dictionary. In cases where the varying parameters are alltunable,findop只需要一个模型汇编即可找到不同参数值的操作点。这种效率对于反复编译的型号尤其有利。

Vary Single Parameter

To vary the value of a single parameter for batch trimming withfindop, specify the parameter grid as a structure having two fields. TheNamefield contains the name of the workspace variable that specifies the parameter. The价值field contains a vector of values for that parameter to take during trimming.

例如,Watertankmodel has three parameters defined as MATLAB workspace variables,a,b, 和A。The following commands specify a parameter grid for the single parameter forA

param.Name ='A';param.Value = Avals;

Here,Avalsis an array specifying the sample values forA

The following table lists some common ways of specifying parameter samples.

Parameter Sample-Space Type How to Specify the Parameter Samples
Linearly varying param.Value = linspace(A_min,A_max,num_samples)
Logarithmically varying param.Value = logspace(A_min,A_max,num_samples)
随机的 param.Value = rand(1,num_samples)
Custom param.Value = custom_vector

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, suppose thatKpidis a vector of PID gains. The first entry in that vector,Kpid, is used as a gain value in a block in your model. Use the following commands to vary that gain using the values given in a vectorKpvals:

param.Name ='Kpid(1)';param.Value = Kpvals;

After you create the structureparam, pass it tofindopas theparaminput argument.

Multidimensional Parameter Grids

When you vary more than one parameter at a time, you generate parameter grids of higher dimension. For example, varying two parameters yields a parameter matrix, and varying three parameters yields a 3-D parameter grid. Consider the following parameter grid used for batch trimming:

Here, you vary the values of three parameters,a,b, 和c。样品形成3 x-4 x-5网格。OP是一个具有相同尺寸的数组,包含相应的修剪工作点对象。

Vary Multiple Parameters

To vary the value of multiple parameters for batch trimming withfindop,将参数样本指定为结构阵列。该结构具有每个参数的条目,其值您的价值变化。每个参数的结构与Vary Single Parameter。You can specify the价值参数作为任何维数的数组的字段。但是,大小价值field must match for all parameters. Corresponding array entries for all the parameters, also referred to as a参数网格点, must map to a specified parameter combination. When the software trims the model, it computes an operating point for each grid point.

Specify Full Grid

Suppose that your model has two parameters whose values you want to vary,ab:

a = { a 1 , a 2 } b = { b 1 , b 2 }

You want to trim the model for every combination ofab, also referred to as afull grid:

{ ( a 1 , b 1 ) , ( a 1 , b 2 ) ( a 2 , b 1 ) , ( a 2 , b 2 ) }

Create a rectangular parameter grid usingndgrid

A1 = 1;A2 = 2;a = [a1 a2];B1 = 3;B2 = 4;B = [B1 B2];[a,b] = ndgrid(a,b)
>> A A = 1 1 2 2 >> B B = 3 4 3 4

Create the structure array,params, that specifies the parameter grid.

params(1).Name ='a';params(1).value = a;参数(2).name ='b';params(2).Value = B;

In general, to specify a full grid forN参数,使用ndgridto obtainNgrid arrays.

[P1,...,PN] = ndgrid(p1,...,pN);

Here,p1,...,pNare the parameter sample vectors.

Create a 1 xNstructure array.

params(1).name ='p1';params(1).value = p1;... params(n).name ='pn';params(n).value = pn;

指定全网格的子集

如果您的模型很复杂,或者您改变了许多参数的价值,则修剪整个网格的模型可能会变得昂贵。在这种情况下,您可以使用类似桌子的方法指定完整网格的子集。使用示例Specify Full Grid, suppose that you want to trim the model for the following combinations ofab:

{ ( a 1 , b 1 ) , ( a 1 , b 2 ) }

Create the structure array,params, that specifies this parameter grid.

A = [a1 a1]; params(1).Name ='a';params(1).value = a;B = [B1 B2];参数(2).name ='b';params(2).Value = B;

Batch Trim Model for Parameter Variations

此示例显示了如何通过不同的参数值获得模型的多个操作点。您可以通过使用修剪的操作点批量对模型进行线性化来研究控制器的鲁棒性,以实现植物变化。

打开Simulin金宝appk模型。

sys ='水箱';OPen_system(sys)

Vary parametersAb在其名义值的10%以内。指定三个值A和四个值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)
操作点watert规范模型ank. (Time-Varying Components Evaluated at time t=0) States: ---------- (1.) watertank/PID Controller/Integrator/Continuous/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在每个修剪操作的命令窗口中显示操作点搜索报告。要抑制报告显示,请创建一个修剪选项集,然后关闭操作点搜索报告显示。

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

使用指定的操作点规范,参数网格和选项集修剪模型。

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

findop修剪每个参数组合的模型。该软件仅使用一个模型汇编。OPis 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 ofOP

OP(1,1)
模型水坦克的操作点。(在时间t = 0上评估的时变组件)状态:----------(1.)watertank/pid控制器/intementator/integrator/continule/intemitator x:1.41(2.)watertank/watertank/water-tank系统/H X:10输入:无------------------------------------

Batch Trim Model at Known States Derived from Parameter Values

This example shows how to batch trim a model when the specified parameter variations affect the known states for trimming.

在里面Batch Trim Model for Parameter Variationsexample, the model is trimmed to meet a single operating point specification that contains unknown states. In other cases, the model states are known for trimming, but depend on the values of the varying parameters. In this case, you cannot batch trim the model using a single operating point specification. You must create a separate specification for each parameter value grid point.

打开Simulin金宝appk模型。

sys ='scdairframeTRIM';OPen_system(sys)

In this model, the aerodynamic forces and moments depend on the speed,$ V $, 和incidence,$\alpha$

Vary the$ V $$\alpha$parameters, and create a 6-by-4 parameter grid.

nA = 6;% number of alpha valuesnV = 4;V值的%数量alphaRange = linspace(-20,20,nA)*pi/180; vRange = linspace(700,1400,nV); [alphaGrid,vGrid] = ndgrid(alphaRange,vRange);

Since some known state values for trimming depend on the values of$ V $$\alpha$, you must create a separate operating point specification object for each parameter combination.

fori = 1:nAforj = 1:NV% Set parameter values in model.alpha_ini = alphaGrid(i,j); v_ini = vGrid(i,j);% Create default specifications based on the specified parameters.OPspec(i,j) = operspec(sys);% Specify which states are known and which states are at steady state.OPspec(i,j).States(1).Known = [1;1]; opspec(i,j).States(1).SteadyState = [0;0]; opspec(i,j).States(3).Known = [1;1]; opspec(i,j).States(3).SteadyState = [0;1]; opspec(i,j).States(2).Known = 1; opspec(i,j).States(2).SteadyState = 0; opspec(i,j).States(4).Known = 0; opspec(i,j).States(4).SteadyState = 1;endend

Create a parameter structure for batch trimming. Specify a name and value grid for each parameter.

params(1).Name ='alpha_ini';params(1).Value = alphaGrid; params(2).Name ='v_ini';params(2).Value = vGrid;

Trim the model using the specified parameter grid and operating point specifications. When you specify an array of operating point specifications and varying parameter values, the dimensions of the specification array must match the parameter grid dimensions.

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

findop修剪每个参数组合的模型。OPis a 6-by-4 array of operating point objects that correspond to the specified parameter grid points.

See Also

||

相关话题