Taylor's ErrorTaylor's Theorem. Suppose NiMlImZH has NiMsJiUibkciIiJGJUYl derivatives for every NiMlInhH for NiMtJSRhYnNHNiMsJiUieEciIiIlImFHISIi <= NiMlImRH (or NiMsJiUiYUciIiIlImRHISIi <= NiMlInhH <= NiMsJiUiYUciIiIlImRHRiU=). ThenNiMtJSJmRzYjJSJ4Rw== = NiMmJSJQRzYjJSJuRw==(NiMlInhH) + NiMmJSJFRzYjJSJuRw==(NiMlInhH)on NiMtJSRhYnNHNiMsJiUieEciIiIlImFHISIi <= NiMlImRH (or NiMsJiUiYUciIiIlImRHISIi <= NiMlInhH <= NiMsJiUiYUciIiIlImRHRiU=) where NiMmJSJQRzYjJSJuRw==(NiMlInhH) = NiMtJSRzdW1HNiQqJiIiIkYnLSUqZmFjdG9yaWFsRzYjJSJrRyEiIi9GKzsiIiElIm5HNiMpJSJmRyUia0c=(NiMlImFH) NiMpLCYlInhHIiIiJSJhRyEiIiUia0c=.Also, if NiMtJSRhYnNHNiMpJSJmRywmJSJuRyIiIkYqRio= <= NiMlIk1H for NiMtJSRhYnNHNiMsJiUieEciIiIlImFHISIi <= NiMlImRH (or NiMsJiUiYUciIiIlImRHISIi <= NiMlInhH <= NiMsJiUiYUciIiIlImRHRiU=), then.NiMtJSRhYnNHNiMtJiUiRUc2IyUibkc2IyUieEc= = NiMtJSRhYnNHNiMsJi0lImZHNiMlInhHIiIiLSYlIlBHNiMlIm5HRikhIiI= <= NiMqJiUiTUciIiItJSpmYWN0b3JpYWxHNiMsJiUibkdGJUYlRiUhIiI=NiMpLSUkYWJzRzYjLCYlInhHIiIiJSJhRyEiIiwmJSJuR0YpRilGKQ==for NiMtJSRhYnNHNiMsJiUieEciIiIlImFHISIi <= NiMlImRH (or NiMsJiUiYUciIiIlImRHISIi <= NiMlInhH <= NiMsJiUiYUciIiIlImRHRiU=).restart:with(plots):We first find the 4th degree Taylor polynomial NiMtJiUiUEc2IyIiJTYjJSJ4Rw== for the function NiMvLSUiZkc2IyUieEcqJkYnIiIiLSUkZXhwRzYjKiQpRiciIiNGKUYp about NiMvJSJ4RyIiIQ==.f:=x*exp(x^2);T[4]:=taylor(f,x=0,5);P[4]:=convert(T[4],polynom);We observe that the third and fourth Taylor polynomials are the same here. We want to find an upper bound for the error NiMtJSRhYnNHNiMtJiUiRUc2IyIiJTYjJSJ4Rw== = NiMtJSRhYnNHNiMsJi0lImZHNiMlInhHIiIiLSYlIlBHNiMiIiVGKSEiIg== for -0.4 <= NiMlInhH <= 0.4. Let's first look at the two graphs, with the Taylor polynomial in blue.plot([f,P[4]],x=-0.4..0.4,color=[red,blue]);The graphs look pretty close. Now, to find a maximum for NiMtJSRhYnNHNiMtJiUiRUc2IyIiJTYjJSJ4Rw== on -0.4 <= NiMlInhH <= 0.4, we need to find the fifth derivative.f5:=diff(f,x$5);We now need to find a number greater than the maximum value of the absolute value of this fifth derivative over the interval. We prefer that this number be chosen as small as possible. We graph the fifth derivative over the interval.plot(f5,x=-0.4..0.4);From the graph it is clear that the absolute value of the fifth derivative never exceeds 150 over our interval, so we choose that number for NiMlIk1H.M:=150;Now we can find an upper bound for the error over the interval using the error formula.maxerror:=M/5!*0.4^5;Graphing the error NiMvLSYlIkVHNiMiIiU2IyUieEcsJi0lImZHRikiIiItJiUiUEdGJ0YpISIi below, we see the error is actually between -.006 and .006, certainly smaller than the maximum we computed.plot(f-P[4],x=-0.4..0.4);Now suppose that we wish to find the Taylor polynomial that will approximate NiMlImZH over this same interval with a maximum error of 0.00001. We need to find the degree NiMlIm5H. We use a while loop indexed on NiMlIm5H. We also use the maximize command.n:=0;
while 1/(n+1)!*maximize(abs(diff(f,x$(n+1))),x=-0.4..0.4)*0.4^(n+1)>0.00001 do
n:=n+1
od;For the NiMlIm5H just calculated, we find the Taylor polynomial NiMtJiUiUEc2IyUibkc2IyUieEc=.T[n]:=taylor(f,x=0,n+1);P[n]:=convert(T[n],polynom);Finally, we graph the error NiMvLSYlIkVHNiMlIm5HNiMlInhHLCYtJSJmR0YpIiIiLSYlIlBHRidGKSEiIg==.plot(f-P[n],x=-0.4..0.4);We see that the error is less than our requirement.