필터 지우기
필터 지우기

How to pass multiple parameters to function handle when invoke 'fmincon'

조회 수: 40 (최근 30일)
Hello, I have a question when I am trying to use 'fmincon' function. The following is my objective function:
function obj = func_obj(x,a,b,c)
obj = x(1)*a + x(2)^2*b + c;
end
And I have both equality and Inequality nonlinear constraint as :
function [c,ceq] = func_con (x,a,b,c,d)
c = x(1)^2 + x(2)^2 -a^2;
ceq = (x(1)*a -x(2)*b)^2 -x(2)*b -d^2;
end
The a,b,c,d are coefficients that need to be changed during every loop, as:
for i = 1: 10
a = ....;
b = ....;
c = ....;
d = ....;
fun = @ func_obj;
nonlcon = @ func_con;
[x,val] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon);% x0,A,b ect. properly configured
end
Since I need varying coefficients in my func_obj and func_cont, and I have both equality and inequality constraints, the way shown in document doesn't seem to help for my application. Could anyone help me on how to pass a,b,c,d properly to the objective and constraint functions? Thanks a lot!

채택된 답변

Walter Roberson
Walter Roberson 2016년 4월 15일
fun = @(x) func_obj(x, a, b, c, d);
nonlcon = @(x) func_con(x, a, b, c, d);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by