Documentation Center

  • Trial Software
  • Product Updates


Specify Independent Parameters to Optimize

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,

  1. Open the Simulink® model.

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

    • In the Model Hierarchy tree, select srotut1 > Model Workspace.

    • Select Add > MATLAB Variable to add a new variable to the model workspace. A new variable with a default name Var appears in the Name column.

    • Double-click Var to make it editable and change the variable name to x. Edit the initial Value to 1.

    • Repeat steps 3 and 4 to add a variable y with an initial value of -0.7.

      The Model Explorer window resembles the following figure.

  3. 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 srotut1 model window, select File > Model Properties > Model Properties.

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

    • Create a MATLAB® file named srotut1_start.

      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.

When you add a new design or uncertain parameter, x and y appear in the dialog box.

    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.

Related Examples

Was this topic helpful?