How to set constraints on parameters in optimization program sdo.optimize (sdo - solve design optimization problem)?

5 Ansichten (letzte 30 Tage)
I am using sdo.optimize (https://nl.mathworks.com/help/sldo/ref/sdo.optimize.html) to run an optimization program and estimate parameters. I need to set constrains on some estimation parameters (e.g. p1 and p2 shall be positive or in a certain range of values). On the Mathworks page that seems possible, inequality constraint are defined as outputs of the optim cost function. But I do not understand how to define them. See optimFcn — Cost function to minimize section in the link, or this image:
How can I set constraints? For example 0<p1<10 and 5<p2<15. Could you provide a simple example code?
More specifically about my problem, I am using an optimization program to identify parameters of a dynamical system, fitting data. I amusing a parametric Simulink model to programmatically define the optimization program in Matlab, using sdo.optimize(https://nl.mathworks.com/help/sldo/ref/sdo.optimize.html). I am basically using spetool ( the App in Simulink to estimate patrameters) from a Matlab script. It means that in Simulink there is a model with input and output ports, and in a Matlab script everything is set up to calculate the cost function by running the Simulink model at each iteration of the optimization process. Everything already runs and works, but I do not know how to programmatically set the constraints on the parameters. I expect it is in some of the fields of sdo or in how the cost function is defined. Maybe it needs to return and additional output that somehow defines the constraints (e.g. posite parameters)?
  1 Kommentar
Devesh Bhasin
Devesh Bhasin am 5 Feb. 2024
Bearbeitet: Devesh Bhasin am 5 Feb. 2024
Hi Milan,
It seems like you are trying to set bounds on the parameters. You can simply specify the bounds using the 'Minimum' and 'Maximum' fields on the parameters.
For example, if you have a model 'myModel' from which you are extracting parameters 'Kp' and 'Ki' using:
p = sdo.getParameterFromModel('myModel',{'Kp','Ki'});
You can then specify the bounds on these parameters using (as an example):
p(1).Minimum = 0 %lower bound of 0 on Kp
p(1).Maximum = 20 %upper bound of 20 on Kp
p(2).Minimum = 0 %lower bound of 0 on Ki
p(2).Maximum = 10 %upper bound of 10 on Ki
If you are trying to set a more complex constraint, you can populate the Cleq,Ceq, leq and/or eq fields in the objective function, depending upon whether the constraint is linear.nonlinear or equality/inequality.
For example, suppose in the objective function with output 'Vals', you want to define a constraint as Kp + Ki<=10. This is a linear equality constraint. So, you can simply add the following line in the objective function:
Vals.leq = p(1)+p(2)-10; % Feasible if the equation's output is <=0
I'd encourage you to look at the following example since it contains both setting of parameter bounds for optimization and nonlinear inequality constraints in the objective function:
I hope that resolves your query.
Regards,
Devesh

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by