Simulink Control Design™ - MathWorks

(Tuis.) #1

To obtain state, input, and output indices based on block paths and state names use
getStateIndex, getInputIndex, and getOutputIndex. Using these commands is
robust to future model changes, such as the addition of model states. Alternatively, you
can manually specify the indices. For more information on the format of indx, indu, and
indy, see getStateIndex, getInputIndex, and getOutputIndex.


If there are no states, inputs, or outputs used by the custom constraint and objective
functions, return the corresponding output argument as [].


For this example, create a mapping that includes only the pressure states for the three
tanks. To do so, define the following custom mapping function.


function [indx,indu,indy] = myMapping(opspec)
indx = [getStateIndex(opspec,'scdTanks/Tank1');
getStateIndex(opspec,'scdTanks/Tank2');
getStateIndex(opspec,'scdTanks/Tank3')];
indu = [];
indy = [];
end


Add the custom mapping to the operating point specification.


opspec.CustomMappingFcn = @myMapping;


When you use a custom mapping function, the indices for the states, inputs, and outputs
in your custom constraint and objective functions must be relative to the order specified
in the mapping function. Update the custom constraint and objective functions with the
new mapping.


function [c_ineq,c_eq] = myConstraintsMap(x,u,y)
c_ineq = [];
c_eq = [x(1)-x(2); % Tank1 pressure - Tank2 pressure
x(2)-x(3)+1]; % Tank2 pressure - Tank3 pressure + 1
end


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


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