MATLAB: How to add parameters to fmincon

fminconparameter optimization

Hello, I am trying to use fmincon but add extra parameters to the function. The function is not a series of equations, therefore it is not like adding constraints. It is rather a parameter dependent computational problem.
lb = [0.1,2]; %left bound
rb = [0.45,3]; %right bound
x0 = lb;
[xopt,funval] = fmincon(@(x1,x2) fun(x1,x2,a,b),x0,[],[],[],[],lb,rb);
what am I doing wrong? Why do I get the error "Not enough input arguments."?
I have just solved a very similar problem but for 1-variable function using fminbnd and it worked!!
a=10;
[x,funval] = fminbnd (@(x) fun(a,x),1,1.5);
I just need a 2-variable solution. Am I using the wrong function? What can be used, if so?
Thank you for your help!

Best Answer

[xopt,funval] = fmincon(@(x) fun(x(1),x(2),a,b),x0,[],[],[],[],lb,rb);
Related Question