## Design Optimization to Meet Step Response Requirements (GUI)

This example shows how to optimize controller parameters to meet step response design requirements using the Response Optimization tool. You specify the design requirements in a Check Step Response Characteristics block.

### Model Structure

The Simulink® model `watertank_stepinput` includes the nonlinear Water-Tank System plant and a PI controller in a single-loop feedback system.

The Step block applies a step input. You can also use other types of input, such as a ramp, to optimize the response generated by such inputs.

This figure shows the Water-Tank System.

Water enters the tank at the top at a rate proportional to the valve opening. The valve opening is proportional to the voltage, V, applied to the pump. The water leaves through an opening in the tank base at a rate that is proportional to the square root of the water height, H. The presence of the square root in the water flow rate results in a nonlinear plant.

The following table describes the variables, parameters, differential equations, states, inputs, and outputs of the Water-Tank System.

 Variables H is the height of water in the tank. Vol is the volume of water in the tank. V is the voltage applied to the pump. Parameters A is the cross-sectional area of the tank. b is a constant related to the flow rate into the tank. a is a constant related to the flow rate out of the tank. Differential equation `$\frac{d}{dt}Vol=A\frac{dH}{dt}=bV-a\sqrt{H}$` States H Inputs V Outputs H

### Design Requirements

The height of water in the tank, `H`, must meet the following step response requirements:

• Rise time less than 2.5 seconds

• Settling time less than 20 seconds

• Overshoot less than 5%

### Specify Step Response Requirements

```sys = 'watertank_stepinput'; open_system(sys);```

2. Add a Check Step Response Characteristics block to the model.

In the Simulink model window, select Library under Simulation. Expand the Simulink Design Optimization node and select Signal Constraints.

Drag and drop the Check Step Response Characteristics block into the model window and connect the block to the output. The block is connected to the signal for which you want to specify design requirements.

3. Specify step response requirements.

Double-click the Check Step Response Characteristics block to open the Sink Block Parameters: Check Step Response Characteristics dialog box.

• In Rise time (seconds), enter `2.5`.

• In Settling time (seconds), enter `20`.

• In % Overshoot, enter `5`.

• In Initial value, enter `1`.

• In Final value, enter `2`.

Click .

Instead of specifying time-domain requirements in the Check blocks, you can specify them in the Response Optimization tool without adding blocks. For an example that uses this approach, see Design Optimization to Track Reference Signal (GUI).

### Specify Design Variables

When you optimize the model response, the software modifies the design variable values to meet the design requirements. You specify which model parameters the software can modify.

1. Open a Response Optimization tool for the model.

In the Simulink model window, from the Apps tab, in the gallery, under Control Systems, select Response Optimization.

Alternatively, in the Sink Block Parameters dialog box, click .

The region bounded by black line segments in Time plot 1 shows the step response requirements that you specified in the Check Step Response Characteristics block.

2. Create a set of design variables.

In the Design Variables Set drop-down list, select New.

The Create Design Variables Set dialog box shows model parameters that you can use as design variables and indicates their locations within the model.

### Note

In your application, if the model parameters you are interested in optimizing are not listed in the Create Design Variables Set dialog box, first specify these parameters as variables. See, Add Model Parameters as Variables for Optimization.

3. Add parameters to the design variables set.

Select `Ki` and `Kp`, and click to add the selected parameters.

The design variables list displays the following variable settings:

• Variable — Variable name

• Value — Current variable value

• Minimum and Maximum — Variable bounds

• Scale — Scaling factor for the variable

4. Limit the design variables to positive values. To do so, enter `0` for the minimum value of each variable in the corresponding Minimum field and press on your keyboard.

Click . A new design variable `DesignVars` is created and appears in the Data area of the Response Optimization tool. You can click the variable to view its contents in the Variable Preview area.

If your model has many parameters, you can first use sensitivity analysis to determine the most influential parameters to optimize, or to obtain initial guesses for the design variables. To open the Sensitivity Analysis tool, in the Response Optimization tab, click Sensitivity Analysis. In the Sensitivity Analysis tool, you can explore the response optimization design space by altering the design variables, identify the parameters that most influence the optimization problem, and compute initial values.

### Optimize Model Response

1. To view the current response of the model, click Plot Model Response.

The plot shows the model output, depicted by the blue line, lies outside the region of the specified step response.

2. Click Optimize.

The default optimization solver `Gradient descent` (`fmincon`) modifies the design variables at each iteration so that the simulated response lies within the design requirement line segments. For more information, see How the Optimization Algorithm Formulates Minimization Problems.

The message `Optimization converged` in the Optimization Progress Report indicates that the optimization solver found a solution that meets the design requirements within the tolerances and parameter bounds. For more information about the outputs displayed in the optimization, see Iterative Display (Optimization Toolbox).

3. Verify that the model output meets the step response requirements.

The plot displays the last five iterations. The final response using the optimized variable parameter appears as the thick blue line. The optimized response lies in the white region bounded by the design requirement line segments and thus meets the requirements.

4. View the optimized parameter values. Click `DesignVars` in Model Workspace and view the updated values in the Variable Preview area.

The optimized values of the design variables are automatically updated in the Simulink model.

### Save the Session

After you optimize the model response to meet design requirements, you can save the Response Optimization tool session which includes the optimized parameter values.

In the Response Optimization tool, in the Response Optimization tab, in the Save Session drop-down list, select Save to model workspace.

In the Save Session window, specify the session name in the Session field.

### Tip

To open the saved session, in the Response Optimization tool for the model, in the Open Session drop-down list, click the Open from model workspace option.