MATLAB: Error using fminbnd function

fminbnd; fcnchk; error

Hello,
I want to compute the max of a function on an interval [a,b].
For that I am using the function fminbnd as follows:
syms x;
f=sqrt(3-2sqrt(x)); a=0; b=1;
dfdx2=-abs(diff(f,2));
dfdx4=-abs(diff(f,4));
M2=-fminbnd(dfdx2,a,b);
M4=-fminbnd(dfdx4,a,b);
The derivatives are calculated just fine but for M2, I get the following error message:
??? Error using ==> fcnchk at 103
If FUN is a MATLAB object, it must have an feval method.
Error in ==> fminbnd at 183
funfcn = fcnchk(funfcn,length(varargin));
Error in ==> programme_test at 5
M2=-fminbnd(dfdx2,a,b);
What am I doing wrong ?

Best Answer

Since you have created your objective function using symbolic variables, you need to convert them to function handles before you can use them to call FMINBND,
Try the following:
syms x;
f=sqrt(3-2*sqrt(x)); a=0; b=1;
dfdx2=-abs(diff(f,2));
dfdx4=-abs(diff(f,4));
F2 = matlabFunction(dfdx2)
F4 = matlabFunction(dfdx4)
M2=-fminbnd(F2,a,b);
M4=-fminbnd(F4,a,b);