Reputation: 85
I am trying to use fminunc function in matlab to solve an unconstrained minimization problem. This function has the format
[x,f] = fminunc (@fun,x0);
Here, the defined fun is an input of fminunc as an objective function. However, my fun function has the format as follow
[fval] = fun (x1,x2,a,b,c)
where $x1$ and $x2$ are vector variables to solve and $a$,$b$ and $c$ are only parameters. I wrote my code as follow to solve this problem,
L = @(x1,x2)fun(x1,x2,a,b,c)
x0 = [x10; x20];
[x,f] = fminunc(L,x0);
However, it got errors saying 'The input arguments are not enough'. Does anyone have any ideas on why this happened?
Upvotes: 0
Views: 215
Reputation: 3460
Your implementation does not work, since you are supposed to submit a function that depends on a vector x
, rather than a bunch of variables x1, x2.
You should replace you function definition by the following:
L = @(x)fun(x,a,b,c)
In the function definition use x(1) and x(2) rather than x1 and x2.
Upvotes: 1