Simulink Control Design™ - MathWorks

(Tuis.) #1

Trimming the model with the custom constraint function produces an operating point
with equal pressures in the first and second tanks, as expected. Also, as expected, there is
a pressure differential of 1 between the third and second tanks.


To examine the final values of the specified constraints, you can check the
CustomEqualityConstr and CustomInequalityConstr properties of the operating
point search report.


rpt1.CustomEqualityConstr


ans =


1.0e-06 *


-0.0001
-0.1540


The near-zero values indicate that the equality constraints are satisfied.


Add Custom Objective Function


To specify a custom objective function, define a function with the same input arguments
as the custom constraint function (x, u, and y), and output argument F. F is an objective
function value to be minimized during trimming, returned as a scalar.


Define the objective function for your application as an algebraic combination of the
states, inputs, and outputs.


For this example, assume that you want to keep the pressure in Tank3 in the range
[16,20]. However, this condition is not always feasible. Therefore, rather than impose
hard constraints, add an objective function to incur a penalty if the pressures are not in
the [16,20] range. To do so, define the following custom objective function.


function F = myObjective(x,u,y)
F = max(x(4)-20, 0) + max(16-x(4), 0);
end


Add the custom objective function to the operating point specification object.


opspec.CustomObjFcn = @myObjective;


Compute Operating Points Using Custom Constraints and Objective Functions
Free download pdf