MATLAB: Someone help me to fix plzzz

floating pointsymbolicSymbolic Math Toolbox

this one i can find max
syms x;
assume(x, 'Real');
f=(2.*x+1).*exp(-x.^2);
xMin = -2; xMax = 1; stepSize = 0.01;
x = xMin:stepSize:xMax ;
y = (2.*x+1).*exp(-x.^2)
[val,idx] = max(y) ;
val
but with this one i can't
syms x;
assume(x, 'Real');
f=(2.*x+1).*exp(-x.^2);
xMin = -2; xMax = 1; stepSize = 0.01;
x = xMin:stepSize:xMax ;
y = f
[val,idx] = max(y) ;
val

Best Answer

Remove the first two lines and place f part after defining x.
OR
Do the following:
syms x real
f(x)=(2.*x+1).*exp(-x.^2);
xMin = -2; xMax = 1; stepSize = 0.01;
x = xMin:stepSize:xMax ;
y = f(x);
[val,idx] = max(y) ;
vpa(val,5) % double(vpa) to get the answer in decimal form
Gives:
ans =
1.5576