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

77 次查看(过去 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