This example shows how to specify independent parameters, that do not appear explicitly in the model, as optimization parameters.
Assume that the parameter Kint in the model srotut1 is related to the parameters x and y according to the relationship Kint=x+y. Also assume that the initial values of x and y are 1 and -0.7, respectively. To tune x and y instead of Kint, first define these parameters in the model workspace. To do this,
Open the Simulink® model.
Add the independent parameters to the model workspace, along with their initial values.
Select View > Model Explorer from the srotut1 window to open the Model Explorer window.
Double-click Var to make it editable and change the variable name to x. Edit the initial Value to 1.
The Model Explorer window resembles the following figure.
Define a Simulation Start function that runs before each simulation of the model. This Simulation Start function defines the relationship between the dependent parameters in the model and the independent parameters in the model workspace.
In the Model Properties window, click the Callbacks tab.
To enter a Simulation start function, select StartFcn, and type the name of a new function. For example, type srotut1_start in the Simulation start function panel. Then, click OK.
The content of the file defines the relationship between the parameters in the model and the parameters in the workspace. For this example, the content resembles the following:
wks = get_param(gcs, 'ModelWorkspace') x = wks.evalin('x') y = wks.evalin('y') Kint = x+y;
Note: You must first use get_param to get the variables independent variables, x and y, from the model workspace. Then define the dependent variable, Kint, in terms of the independent variables.
Caution Avoid adding independent parameters together with their corresponding dependent parameters to the lists of tuned and uncertain parameters. Otherwise, the optimization could give incorrect results. For example, when a parameter c depends on the parameters a and b avoid adding all three parameters to the lists.