Frage

Say i have a function f(X) which i want to minimize with constraints such that some other functions- A(X) = 0 and B(X) = 0 and 0 < C(X) < pi. There are many algorithms to do it, but to make my life easier, i want to use built in function fmincon() in matlab. So i read this documentation: http://www.mathworks.com/help/optim/ug/fmincon.html

But I don't understand how I should I pass the parameters to solve my problem in specific. How do I do it? Can I do it at all?

War es hilfreich?

Lösung

Use the nonlcon parameter of fmincon (I'm assuming here your constraints are nonlinear?). Then A(X) and B(X) are fine but for C(X) it must be in the form c(X) < 0 so you'll need to break it into two constraints of that form.

I pulled this example of how to specify a function for nonlcon from elsewhere in the documentation:

function [c,ceq]=myNonlinearContraints(x)
%First deal with your nonlinear equalities
c(1) = A(X);
c(2) = B(X);
%Then your inequalities transformed to be in the form ceq < 0
ceq(1) = -C(X);
ceq(2) = C(X) - pi;

Andere Tipps

See if the functions A,B are linear or nonlinear. That is maybe A(X) is simply a integral, then the interpretation should be that it is linear. It does actually make a difference if you supply a linear constraint as nonlinear.

If they are nonlinear, then create a

function [c,ceq] = nonlcon(X) 

which gives out the equality constraint value (ceq) and inequality constraint value (c). Remember that inequality constraints are interpreted as

ineq(X) < 0

So you need to compute it that way.

C(X) seems to be a trigonometric function, so it will also be part of nonlcon function. This nonlcon, you will pass to fmincon as an argument. Nonlcon is called for a specific value of X and it returns the constraint value. Pass your lower and upper bounds if any and try the optimization for different initial points x0. For some problems, more than one solution can be found.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top