Construct optimisation constraints vector with anonymous function.

1 vue (au cours des 30 derniers jours)
Afonso Silva
Afonso Silva le 18 Août 2015
Modifié(e) : blaat le 18 Août 2015
Hi, I am using Opti tools to optimise a nonlinearly constrained function. According to the tutorial, non-linear constraints are declared through an anonymous function such as: nlcon = @(x) x(1).^3 + 2*x(2) It happens that my optimisation problem is quite big, so all my linear constraints were constructed using a basic 'for' routine. However, I failed doing the same with anonymous functions. How can I sequentially add new nonlinear constraints to nlcon?
Here is a simple example of what I woul like to do:
While i < k
nlnon(i) = @(x) x(1).^3 + 2*x(2)
if c >z
nlnon(i+1) = @(x) x(4).^9 + 2
else
nlnon(i+1) = @(x) x(4).^2 + 2
end
i = i+2;
k = k+1;
end
Thank you, Best Regards

Réponses (1)

blaat
blaat le 18 Août 2015
Modifié(e) : blaat le 18 Août 2015
You can also call functions within an anonymous function, e.g.,
param1 = 6;
param2 = 0.5;
nlcon = @(x)calculateconstraint(x, param1, param2);
So place the computation for your constraint in a function (e.g., calculateconstraint), and refer to it as above.

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by