Write nonlinear constraint to fmincon

조회 수: 5 (최근 30일)
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013년 1월 17일
I am using fmincon to optimize a vectorized function (myfun) of five variables (x). This function has also some parameters (k, l, m, n) which I am passing to fmincon. What I am doing is shown below:
p=@(x)myfun(x, k, l, m, n);
[xmin, pmin]=fmincon(p, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
My question is how am I going to write the nonlinear equality which I have in my problem. I have written another function about the nonlinear equality in which x is the variables used in myfun and L is a parameter that I would like to pass inside the constraint. See below:
function [c,ceq]=pitch(x,L)
c=[];
ceq=x(3)*x(5)-L;
end
The problem is that I don't know how to write inside the fmincon the constraint. I have written this:
nonlcon=@(x)pitch(x,L)
which results in an error. I would appreciate your answers. Thank you.
  댓글 수: 1
Matt Kindig
Matt Kindig 2013년 1월 17일
Could you post the error for us?

댓글을 달려면 로그인하십시오.

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 1월 17일
Thanks for the error, it appears that your objective function myfun takes 'x' as a 4x1 vector while your nonlinear constraint assumes that there is atleast x(5) in the line:
ceq=x(3)*x(5)-L;
that is atleast a 5x1 vector.
You might want to check that.

추가 답변 (4개)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013년 1월 17일
Attempted to access x(5); index out of bounds because numel(x)=4.
Error in power_fraction2 (line 7) Pf=(2*Rf*jmpp*x(2)^3*(x(3) - x(1))^2)/(3*x(3)*x(5)*x(3)*Vmpp*x(1));
Error in @(x)power_fraction2(x,jmpp,Vmpp,Rito,Rb,Rf,rc)
Error in fmincon (line 601) initVals.f = feval(funfcn{3},X,varargin{:});
Error in opt_power (line 48) [xmin, pmin]=fmincon(p, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013년 1월 17일
Thank you Benji for the answer. This would make sense if I had not defined x(5) in the function that I would like to optimize. I am posting an equation included in myfun as an example.
Pf=(2*Rf*jmpp*x(2)^3*(x(3) - x(1))^2)/(3*x(3)*x(5)*x(3)*Vmpp*x(1));
So it is clearly stated in the function that vector x has 5 elements. What do you think?

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013년 1월 17일
I am sorry. Indeed I had a mistake in the boundaries. I had four elements instead of 5.

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013년 1월 17일
I would like one of the optimized variables to be an integer. Is there a way to achieve this with fmincon. In global optimization toolbox the Genetic Algorithm Solver can achieve that as far as I know. Am I correct or this can be done through fmincon?
  댓글 수: 3
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013년 1월 17일
So Matt I have to use the Genetic Algorithm.
Shashank Prasanna
Shashank Prasanna 2013년 1월 17일
Giorgos, you are right this options is currently only available in Genetic Algorithm. Other optimization tools as yet dont support mixed integer programming.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by