Here, x, u, and y are vectors of mapped states, inputs, and outputs, respectively. These
vectors contain the mapped values specified in indx, indu, and indy, respectively.
Add the updated custom functions to the operating point specification.
opspec.CustomConstrFcn = @myConstraintsMap;
opspec.CustomObjFcn = @myObjectiveMap;
Trim the model using the custom mapping, and view the trimmed states, which match the
previous results in op2.
[op3,rpt3] = findop(mdl,opspec,opt);
op3.States
(1.) scdTanks/Inertia
x: 0
(2.) scdTanks/Tank1
x: 15
(3.) scdTanks/Tank2
x: 15
(4.) scdTanks/Tank3
x: 16
Add Analytic Gradients to Custom Functions
For faster or more reliable computations, you can add analytic gradients to your custom
constraint and objective functions. Adding gradients can reduce the number of function
calls during optimization and potentially improve the accuracy of the optimization result.
If you specify gradients, you must specify them for both the custom constraint and
objective functions. (Gradients for custom trimming are not supported for Simscape™
models.)
To define the gradient of a given constraint or objective function, take the derivative of
the function with respect to a given state, input, or output. For example, if the objective
function is
F = (u(1)+3)^2 + y(1)^2
then the gradient of F with respect to u(1) is
G = 2*(u(1)+3)
To add gradients to your custom constraint function, specify the following additional
output arguments:
1 Steady-State Operating Points