How to pass multiple parameters to function handle when invoke 'fmincon'
조회 수: 34 (최근 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!
댓글 수: 0
채택된 답변
Walter Roberson
2016년 4월 15일
fun = @(x) func_obj(x, a, b, c, d);
nonlcon = @(x) func_con(x, a, b, c, d);
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!