MATLAB: Anonymous function.problem

anonymous functioninline()

Dear all,
I met a problem, xmax = fminbnd(@(x)(f(x)), 0, 5) this line is ok, however, xmax = fminbnd(@(x)(-f(x)), 0, 5) get an error, if I use inline , xmax = fminbnd(inline(-f(x)), 0, 5), it is also ok, I don't know what is the problem. Could anyone give me the answer.
Thanks!
matlab2018a win7
clearvars
syms t x
f = @(x)int(t*exp(-t^2),t, 0, x);
xmin = fminbnd(f, 0, 5)
fxmin = double( f(xmin) )
xmax = fminbnd(@(x)(f(x)), 0, 5) %ok
xmax = fminbnd(inline(-f(x)), 0, 5) %ok
xmax = fminbnd(@(x)(-f(x)), 0, 5) %error
xmax = fminbnd(@(x)(f(x)*(-1)), 0, 5) %error
prob.PNG

Best Answer

clearvars
syms t x
f = int(t*exp(-t^2),t, 0, x);
f=matlabFunction(f) %learn about matlabFunction
xmin = fminbnd(@(x)f(x), 0, 5)
fxmin = double( f(xmin) )
xmax = fminbnd(@(x)-f(x), 0, 5)