Optimization Toolbox    

Multiobjective Examples

The previous examples involved problems with a single objective function. This section demonstrates solving problems with multiobjective functions using lsqnonlin, fminimax, and fgoalattain. Included is an example of how to optimize parameters in a Simulink model.

Simulink Example

Let's say that you want to optimize the control parameters in the Simulink model optsim.mdl. (This model can be found in the Optimization Toolbox optim directory. Note that Simulink must be installed on your system to load this model.) The model includes a nonlinear process plant modeled as a Simulink block diagram shown in Figure 2-1, Plant with Actuator Saturation.

Figure 2-1: Plant with Actuator Saturation

The plant is an under-damped third-order model with actuator limits. The actuator limits are a saturation limit and a slew rate limit. The actuator saturation limit cuts off input values greater than 2 units or less than -2 units. The slew rate limit of the actuator is 0.8 units/sec. The open-loop response of the system to a step input is shown in Figure 2-2, Closed-Loop Response. You can see this response by opening the model (type optsim at the command line or click the model name), and selecting Start from the Simulation menu. The response plots to the scope.

Figure 2-2: Closed-Loop Response

The problem is to design a feedback control loop that tracks a unit step input to the system. The closed-loop plant is entered in terms of the blocks where the plant and actuator have been placed in a hierarchical Subsystem block. A Scope block displays output trajectories during the design process. See Figure 2-3, Closed-Loop Model.

Figure 2-3: Closed-Loop Model

One way to solve this problem is to minimize the error between the output and the input signal. The variables are the parameters of the PID controller. If you only need to minimize the error at one time unit, it would be a single objective function. But the goal is to minimize the error for all time steps from 0 to 100, thus producing a multiobjective function (one function for each time step).

The routine lsqnonlin is used to perform a least-squares fit on the tracking of the output. This is defined via a MATLAB function in the file tracklsq.m, shown below, that defines the error signal. The error signal is yout, the output computed by calling sim, minus the input signal 1.

The function tracklsq must run the simulation. The simulation can be run either in the base workspace or the current workspace, i.e., the workspace of the function calling sim, which in this case is tracklsq's workspace. In this example, the simset command is used to tell sim to run the simulation in the current workspace by setting 'SrcWorkspace' to 'Current'.

To run the simulation in optsim, the variables Kp, Ki, Kd, a1, and a2 (a1 and a2 are variables in the Plant block) must all be defined. Kp, Ki, and Kd are the variables to be optimized. You can initialize a1 and a2 before calling lsqnonlin and then pass these two variables as additional arguments. lsqnonlin then passes a1 and a2 to tracklsq each time it is called, so you do not have to use global variables.

After choosing a solver using the simset function, the simulation is run using sim. The simulation is performed using a fixed-step fifth-order method to 100 seconds. When the simulation completes, the variables tout, xout, and yout are now in the current workspace (that is, the workspace of tracklsq). The Outport block is used in the block diagram model to put yout into the current workspace at the end of the simulation.

Step 1: Write an M-file tracklsq.m.

Step 2: Invoke optimization routine.

The variable options passed to lsqnonlin defines the criteria and display characteristics. In this case you ask for output, use the medium-scale algorithm, and give termination tolerances for the step and objective function on the order of 0.001.

The optimization gives the solution for the proportional, integral, and derivative (Kp, Ki, Kd) gains of the controller after 64 function evaluations:

The resulting closed-loop step response is shown in Figure 2-4.

Figure 2-4: Closed-Loop Response Using lsqnonlin

Another solution approach is to use the fminimax function. In this case, rather than minimizing the error between the output and the input signal, you minimize the maximum value of the output at any time t between 0 and 100. Then in the function trackmmobj the objective function is simply the output yout returned by the sim command. But minimizing the maximum output at all time steps may force the output far below unity for some time steps. To keep the output above 0.95 after the first 20 seconds, in the constraint function trackkmmcon add a constraint yout >= 0.95 from t=20 to t=100. Because constraints must be in the form g <= 0, the constraint in the function is g = -yout(20:100)+.95.

Both trackmmobj and trackmmcon use the result yout from sim, calculated from the current pid values. The nonlinear constraint function is always called immediately after the objective function in fmincon, fminimax, fgoalattain, and fseminf with the same values. Thus you can avoid calling the simulation twice by using assignin to assign the current value of F to the variable F_TRACKMMOBJ in the base workspace. Then the first step in trackmmcon is to use evalin to evaluate the variable F_TRACKMMOBJ in the base workspace, and assign the result to F locally in trackmmcon.

Step 1: Write an M-file trackmmobj.m to compute objective function.

Step 2: Write an M-file trackmmcon.m to compute nonlinear constraints.

Note that fminimax passes a1 and a2 to the objective and constraint values, so trackmmcon needs input arguments for these variables even though it does not use them.

Step 3: Invoke constrained optimization routine.

resulting in

The last value shown in the MAX{F,constraints} column of the output shows that the maximum value for all the time steps is 0.9996. The closed loop response with this result is shown in Figure 2-5, Closed-Loop Response Using fminimax.

This solution differs from the lsqnonlin solution, because you are solving different problem formulations.

Figure 2-5: Closed-Loop Response Using fminimax

Signal Processing Example

Consider designing a linear-phase Finite Impulse Response (FIR) filter. The problem is to design a lowpass filter with magnitude one at all frequencies between 0 and 0.1 Hz and magnitude zero between 0.15 and 0.5 Hz.

The frequency response H(f) for such a filter is defined by

     (2-6)  

where A(f) is the magnitude of the frequency response. One solution is to apply a goal attainment method to the magnitude of the frequency response. Given a function that computes the magnitude, the function fgoalattain will attempt to vary the magnitude coefficients a(n) until the magnitude response matches the desired response within some tolerance. The function that computes the magnitude response is given in filtmin.m. This function takes a, the magnitude function coefficients, and w, the discretization of the frequency domain we are interested in.

To set up a goal attainment problem, you must specify the goal and weights for the problem. For frequencies between 0 and 0.1, the goal is one. For frequencies between 0.15 and 0.5, the goal is zero. Frequencies between 0.1 and 0.15 are not specified, so no goals or weights are needed in this range.

This information is stored in the variable goal passed to fgoalattain. The length of goal is the same as the length returned by the function filtmin. So that the goals are equally satisfied, usually weight would be set to abs(goal). However, since some of the goals are zero, the effect of using weight=abs(goal) will force the objectives with weight 0 to be satisfied as hard constraints, and the objectives with weight 1 possibly to be underattained (see Goal Attainment Method). Because all the goals are close in magnitude, using a weight of unity for all goals will give them equal priority. (Using abs(goal) for the weights is more important when the magnitude of goal differs more significantly.) Also, setting

specifies that each objective should be as near as possible to its goal value (neither greater nor less than).

Step 1: Write an M-file filtmin.m.

Step 2: Invoke optimization routine.

Compare the magnitude response computed with the initial coefficients and the final coefficients (Figure 2-6). Note that you could use the remez function in the Signal Processing Toolbox to design this filter.

Figure 2-6: Magnitude Response with Initial and Final Magnitude Coefficients


  Nonlinear Equations with Finite-Difference Jacobian Large-Scale Examples