Clear Filters
Clear Filters

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

40 views (last 30 days)
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!

Accepted Answer

Walter Roberson
Walter Roberson on 15 Apr 2016
fun = @(x) func_obj(x, a, b, c, d);
nonlcon = @(x) func_con(x, a, b, c, d);

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!