MATLAB: Using fminunc()

fminunc

Hello,
I want to use x = fminunc(fun,x0);
For a litle test I choosed following structure:
fun=[x1+x2 ; sin(x3)];
fun==> 2×1 sym
x0 ==> 3×1 double
ERROR:
Error using optimfcnchk (line 288) If FUN is a MATLAB object, it must have an feval method.
Error in fminunc (line 239) funfcn = optimfcnchk(FUN,'fminunc',length(varargin),funValCheck,gradflag,hessflag); Thanks!
Btw: I know, x0 is near the solution BUT I don't know if the solution is a Minimum or Maximum ;(

Best Answer

what do you want? what is the function you want to optimize for? fminunc searches for a minimum, but for instance x1+x2 is unbounded below (solution: x1=-inf, x2=-inf) and for sin(x3) has infinitely many minima...
anyway the format for fminunc (and fmincon) is the following:
myfunction=@(x)x(1)+x(2)+sin(x3);
x0=[1, 4, 10];
[x,y]=fminunc(myfunction,x0);
note that the my example does not have a solution...