MATLAB: Someone help me plzzz :(

duplicate postfloating pointMATLABsymbolicSymbolic Math Toolbox

tic
syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
for i=1:25
y(i)=diff(f(x),i);
end
fun=matlabFunction(y');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
for i=1:25
if maxres(i)<0.001
break
end
end
someone can tell me the way to find max y(i) = diff (f(x),i) in every step and check it
if max(y(i))< 0.001 then stop the loop

Best Answer

syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
y=zeros(1,25);
for i=1:25
y(i)=diff(f(x),i);
end
fun=matlabFunction(y.');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
maxres(abs(maxres-0.001)<1e-4) % will return empty because none of the results satisfy the condition