MATLAB: Help me to find max :((

floating pointMATLAB

syms x;
f(x) = (2.*x-1).*sin(pi.*x);
xMin = -2; xMax = 1; stepSize = 0.01;
for i=1:5
y=diff(f(x),i);
[val,idx] = max(y) ;%Error using sym/max (line 101)
%Input arguments must be convertible to floating-point numbers.
eval(val)
end
help me fix it plz

Best Answer

Hi,
two steps. Symbolic finding the derivatives and then calculate numeric over the functions you got.
syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
for i=1:5
y(i)=diff(f(x),i);
end
fun=matlabFunction(y');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
Best regards
Stephan