MATLAB: I don’t know how to fix it Help me :(

floating pointMATLABsymbolicSymbolic Math Toolbox

syms x;
e=0.001;
a=-2;
b=1;
f(x)=(2.*x-1).*sin(pi.*x);
Pn10(x)=taylor(f,'order',10);
xMin = a; xMax = b; stepSize = 0.01;
x = xMin:stepSize:xMax ;
terms=children(Pn10);
for i=1:10
y=terms(i);
[val,idx] = max(y) ;
ans1=vpa(val,5)
if ans1 < e
break
end
end
i
i want to find i when Max(terms(i)<e)

Best Answer

No loops needed:
syms x;
ee = 0.001;
a = -2;
b = 1;
f(x) = (2.*x-1).*sin(pi.*x);
Pn10(x) = taylor(f,'order',10);
xMin = a; xMax = b; stepSize = 0.01;
terms = children(Pn10);
y(x) = terms;
x = xMin:stepSize:xMax ;
Y = cellfun(@max,y(x)) ;
a = vpa(Y)-ee;
Final_answer = vpa(a(a < 1e-4))