Multiple Non linear constraints for fmincon optimization

조회 수: 25 (최근 30일)
Jared
Jared 2012년 5월 5일
댓글: Matt J 2022년 5월 1일
I would like to be able to use multiple non linear constraints with the fmincon optimization function. Currently fmincon works with both of my nonlcon function handles. Both of them are only using c(x) < 0, and not ceq(x) = 0.
So I have a function
[c,ceq] = cost(x, ..., ..., ...)
and corresponding function handle
nonlincon1 = @(x) cost(x, ..., ..., ...);
and
[c,ceq] = force(x, ..., ..., ...)
and corresponding function handle
nonlincon1 = @(x) force(x, ..., ..., ...);
Like I said I can pass the non linear constraint nonlincon1, or nonlincon2 with fmincon...
[xOpt,optimCost] = fmincon(f,x0,[],[],[],[],lb,ub,nonlcon1,options);
[xOpt,optimCost] = fmincon(f,x0,[],[],[],[],lb,ub,nonlcon2,options);
but I am not sure how to use both function handles as constraints at once. I have tried putting them in cells and the function works but I get some a message I do not quite understand, and the optimization is ignoring the nonlincon2 constraint.
[xOpt,optimCost,exitflag] = fmincon(f,x0,[],[],[],[],lb,ub,{nonlcon1;nonlcon2},options);
Warning: Constraint gradient function provided but OPTIONS.GradConstr = 'off'; ignoring constraint gradient function and using finite-differencing. Rerun with
OPTIONS.GradConstr = 'on' to use constraint gradient function.
Any ideas?
  댓글 수: 3
Joshua Hoegerman
Joshua Hoegerman 2022년 5월 1일
This doesnt work, you cant store multiple function handles within a standard array, you need to use a cell array which fmincon doesnt accept
Matt J
Matt J 2022년 5월 1일
It should work, provided cost() and force() are visible to the function somehow, e.g., they are local functions.

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

답변 (2개)

Alan Weiss
Alan Weiss 2012년 5월 7일
Alan Weiss
MATLAB mathematical toolbox documentation

Jared
Jared 2012년 5월 5일
Okay, so from the Warning above I have turned on the GradConstr option and I get an error,
options = optimset('Algorithm','sqp','Display','iter','GradConstr','on');
Error using fmincon (line 759)
Gradient of nonlinear inequality constraints must have size 2-by-1.\
I think that I am heading down the wrong track with this....

카테고리

Help CenterFile Exchange에서 Linear Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by