Module for Maclaurin and Taylor Polynomials

Numerical Methods using Mathematica  
Complementary software supplements for   
Numerical Methods textbooks  
John H. Mathews and Kurtis Fink, 2004

Background.

When a Taylor series is truncated to a finite number of terms the result is a Taylor polynomial.  A Taylor series expanded about (Subscript[x, 0]) = 0, is called a Maclarin series.  These Taylor (and Maclaurin) polynomials are used to numerically approximate functions.  We attribute much of the founding theory to Brook Taylor (1685-1731), Colin Maclaurin (1698-1746) and Joseph-Louis Lagrange (1736-1813).

Theorem (Taylor Polynomial Approximation).  Assume that  f∈(C^(n + 1))[(Subscript[x, 0]) - R,(Subscript[x, 0]) + R],  then 

	f (x) = (Subscript[P, n]) (x) + (Subscript[R, n]) (x),
	
where (Subscript[P, n]) (x) is a polynomial that can be used to approximate  f (x), and we write  

	f (x) ≈ (Subscript[P, n]) (x)=(∑_(k = 0)^n)((Derivative[k][f]((Subscript[x, 0])))/(k!))(((x - 
                    (Subscript[x, 0])))^k).

The remainder term (Subscript[R, n]) (x)has the form

	(Subscript[R, n]) (x)=((Derivative[n + 1][f](c))/((n + 
                  1)!))(((x - (Subscript[x, 0])))^(n + 1)),

for some value c = c (x) that lies between c and (Subscript[x, 0]).  The formula (Subscript[R, n]) (x) is referred to as the Lagrange form of the remainder.

Proof  Maclaurin and Taylor Polynomials  Maclaurin and Taylor Polynomials

Corollary 1.  Assume that  f∈(C^(n + 1))[(Subscript[x, 0]) - R,(Subscript[x, 0]) + R], and that the Taylor polynomial of degree n for f (x) is P (x)=(∑_(k = 0)^n)((Derivative[k][f]((Subscript[x, 0])))/(k!))(((x - 
                    (Subscript[x, 0])))^k), then 

	Derivative[k][P]((Subscript[x, 0])) = Derivative[k][f]((Subscript[x, 0]))   for  k = 0,1,2,...,n.

Proof  Maclaurin and Taylor Polynomials  Maclaurin and Taylor Polynomials

Corollary 2.  Assume that  f∈(C^(n + 1))[(Subscript[x, 0]) - R,(Subscript[x, 0]) + R], and that the Taylor polynomial of degree n for f (x) is P (x)=(∑_(k = 0)^n)((Derivative[k][f]((Subscript[x, 0])))/(k!))(((x - 
                    (Subscript[x, 0])))^k), then 

	\(\(\(|\)\(\(R\_n\) \((x)\)\)\(|\)\(\ \)\(\(≤\)\(\(M\/\(\((n + 1)\)!\)\) R\^\(n + 1\)\)\)\)\),

where  M = max{|Derivative[n + 1][f](x)|:  (Subscript[x, 0]) - R  ≤  x  ≤  
                (Subscript[x, 0]) + R}.

Proof  Maclaurin and Taylor Polynomials  Maclaurin and Taylor Polynomials

Animations (Maclaurin and Taylor Polynomials  Maclaurin and Taylor Polynomials).  Internet hyperlinks to animations.

Computer Programs  Maclaurin and Taylor Polynomials  Maclaurin and Taylor Polynomials

Example 1.  Consider the function  f[x] = (1/(1  +  (x^2))).  
1 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x]. 
1 (b).  Investigate the error term (Subscript[E, n]) (x)for the Maclaurin polynomial of degree n = 10 over the interval  [-0.5, 0.5].  
1 (c).  Find the terms up to  (x^50)  in the Maclaurin series and see how close it approximates  f[x].

Solution 1 (a).

1 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x].

f[x_] = (1/(1 + (x^2))); 

    T  =  Series[f[x], {x, 0, 10}]; 

    s[x_] = Normal[T]; 

    Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Remark.  If you just find the "Series" it will include a "Big O"  term, which cannot be used in either evaluations or graphing, we eliminate it with the command "Normal."  The "Big O"  term lets us know the power of x in the "remainder."

Series[f[x], {x, 0, 10}]

Normal[Series[f[x], {x, 0, 10}] ]

Aside.  Of course the "full" Maclaurin series has an infinite number of terms.  Mathematica is capable of finding sums of infinite series.  

The following is just for fun !

There are two ways to get infinite sums, the old way and the new way.  First sum the series  \(∑\+\(n = 0\)\%∞\(\((\(-1\))\)\^n\) \((1\/2)\)\^\(2  n\)\).  The "telegraph" command is:

Clear[n];

    Sum[(((-1))^n) ((((1/2)))^(2  n)), {n, 0, 
        Infinity}]

The "symbolic" command is:

(∑_(n = 0)^∞)(((-1))^n) ((((1/2)))^(2  
              n))

Summation is located on the BasicInput palette.
Now sum the power series  (∑_(n = 0)^∞)(((-1))^n) (x^(2  n)).

(∑_(n = 0)^∞)(((-1))^n) (x^(2  
              n))

Now graph f[x] and the Maclaurin polynomial s[x] over the interval [-1, 1].

Needs["Graphics`Colors`"]; 

    Plot[{f[x], s[x]}, {x, -1, 1}, 
        PlotStyle -> {Magenta, Green}]; 

    Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Notice that there is a significant amount of error near  x = ±1.  Let's investigate a smaller interval.
Graph  f[x]  and the Maclaurin polynomial  s[x]  over the interval  [-0.5, 0.5].

Needs["Graphics`Colors`"]; 

    Plot[{f[x], s[x]}, {x, -0.5, 0.5}, 
        PlotRange -> {{-0.5, 0.5}, {0, 1}}, 
        PlotStyle -> {Magenta, Green}]; 

    Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Background for part 1 (b).  Use the fact that the series is "alternating" to investigate the error for the Maclaurin polynomial of degree n = 10 over the interval  [-0.5, 0.5].

Now look closely at the "error" when the series is used to approximate the function.  It becomes infinite near x = 1.  For this reason we work on smaller intervals, in this case we chose  [-0.5, 0.5].  How close are were the two curves in part (a) ?

e[x_] = Simplify[f[x] - s[x]]; 

    Plot[f[x] - s[x], {x, -0.5, 0.5}, 
        PlotRange -> {{-0.5, 0.5}, {0, 0.0002}}, 
        PlotStyle -> Blue]; 

    Print["e[x] = ", e[x] ];

Observation.  We used the "Simplify" command to form e[x], without this command it would have looked different.

f[x]-s[x]

This series is "very nice" because it is alternating, and for that reason the error bound is the magnitude of the "next term" in the series.

errorbound = Abs[ 
        (x^12) ]

The error bound for the entire interval  [-0.5, 0.5] is

Abs[(((0.5))^12) ]

This estimate is "conservative" and is a little larger than the "actual" maximum error which occurred at   x = ±0.5

Print[" e[0.5] = ", e[0.5], "\n", "e[-0.5] = ", 
        e[-0.5] ];

Solution 1 (b).

Background. Lagrange form of the Remainder.  The Lagrange form of the error is  R[x, c] = ((Derivative[11][f][c])/(11!))(x^11)  where  c  is known to exist and lies somewhere between  0  and  x.

Clear[c];
R[x_, c_] = ((Derivative[11][f][c])/(11!))(x^11); 
Print["The Lagrange form of the remainder \
is", "\n"]; 
Print["R[x,c] = 
(f^((11)))[c]/(11!)(x^11) where c lies somewhere between 0 and x.","\n"]; 
Print["R[x,c] = ", 
            Together[R[x, c]] ];

First we need to bound the size of the term  ((Derivative[11][f][c])/(11!))  for values of  c  in the interval  -0.5 ≤ c ≤ 0.5.  This can easily be done graphically, but to do it analytically with derivatives is quite messy.  We choose to look at the following graph to see what is happening.

Plot[{-0.909253,0.909253,((Derivative[11][f][c])/(11!))},{c, -0.5, 0.5},PlotRange -> {{-0.5, 0.5}, {-1.0, 1.0}},PlotStyle -> {Cyan, Cyan, Blue}]; 
Print["
(f^((11)))[c]/(11!) = ",Together[((Derivative[11][f][c])/(11!))] ];

How big does  ("\!\(f\^\((11)\)\)[c]"/(11!))  get ?  Looking at the graph we can estimate it to be  |((Derivative[11][f][c])/(11!))|≤ 0.9092530243443296`.  

That's good enough.

How big does the error  R[x, c] = ((Derivative[11][f][c])/(11!))(x^11)  get ?  Notice that |R[x, c]| = |((Derivative[11][f][c])/(11!))||(x^11)|.  
We will use the bound the first portion|((Derivative[11][f][c])/(11!))|≤ 0.91  and  then bound the portion  |(x^11)|  over the interval  [-0.5, 0.5]  by evaluating it at  x = ±0.5

\(\(\(Print[\*""|(x^11)| ≤ "", \((0.5)\)\^11];\)\(\ \)\)\)

Now multiply the two numbers together to find the error bound for Lagrange's remainder formula. 

	|R[x, 
            c]|≤ 0.0004881*0.909253 = 
        0.000443806  

This is a little larger than the actual maximum error we found. Remember is an "error bound."

Print[" e[0.5] = ", e[0.5], "\n", "e[-0.5] = ", 
        e[-0.5] ];

Solution 1 (c).

1 (c).  Find the terms up to  (x^50)  in the Maclaurin series and see how close it approximates  f[x].

Go ahead "enjoy" and add terms in the series up to (x^50), then plot the functions over the interval [-0.8, 0.8].

s[x_] = 
        Normal[Series[f[x], {x, 0, 50}] ]; 

    Plot[{f[x], s[x]}, {x, -0.8, 0.8}, 
        PlotRange -> {{-0.8, 0.8}, {0, 1}}, 
        PlotStyle -> {Magenta, Green}]; 

    Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Aside.  Mathematica actually computes the higher derivatives of f[x] when calculating the Taylor series. Suppose you had to find the formula for the first 10 derivatives of f[x].  Could "you" do it ?  Would you want to do it ?

For[i = 0,i ≤ 10,i++,
Print[Derivative[i]["f"],"[x] = ",Together[Derivative[i][f][x]]] ;];

Aside.  The function  f[x] = (1/(1  +  (x^2)))  is "infinitely differentiable", that is it has a derivatives of all orders.  And the graph looks really smooth and nice for "all x."

Plot[f[x], {x, -4, 4}, 
        PlotStyle -> Magenta]; 

    Print["f[x] = ", f[x] ];

So, why is the Maclaurin series severely restricted to the interval (-1,1).  The answer lies in the study of complex numbers, we must  look at the denominator and see where it vanishes.

eqn  = Denominator[f[x]] == 0; 

    solset = Solve[eqn, x]; 

    Print["f[x] = ", f[x] ]; 

    Print[eqn]; 

    Print[solset, "\n"]; 

    Print[" f[\[ImaginaryI]] = ", 
        f[I] ]; 

    Print["f[-\[ImaginaryI]] = ", 
        f[-I] ];

The values ±i  are called singularities of  f[x]  and the radius of convergence is the distance from the origin to the closest one.  But this topic must be left to another course called "complex analysis" which is offered each spring.  All computer algebra systems such as Mathematica or Maple or Derive do there underlying computations using complex numbers.  It is the mathematicians way to do it, and it is really fun to work with complex functions.

Example 2.  Consider the function  f[x] = Cos[x].  
2 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x]. 
2 (b).  Investigate the error term (Subscript[E, n]) (x)for the Maclaurin polynomial of degree n = 10 over the interval  [-2.0, 2.0].  
2 (c).  Find the terms up to  (x^20)  in the Maclaurin series and see how close it approximates  f[x].

Solution 2 (a).

2 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x].

f[x_] = Cos[x]; 
T  =  Series[f[x], {x, 0, 10}]; 
s[x_] = Normal[T]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Remark.  If you just find the "Series" it will include a "Big O"  term, which cannot be used in either evaluations or graphing, we eliminate it with the command "Normal."  The "Big O"  term lets us know the power of x in the "remainder."

Series[f[x], {x, 0, 10}]

Normal[Series[f[x], {x, 0, 10}] ]

Aside.  Of course the "full" Maclaurin series has an infinite number of terms.  Mathematica is capable of finding sums of infinite series.  

The following is just for fun !

There are two ways to get infinite sums, the old way and the new way.

Clear[n];
g[
        x_] = Sum[(((-1))^n) 
          ((x^(2  n))/((2  n)!)), {n, 0, 
          Infinity}]

FullSimplify[g[x]]

The "symbolic" command is:

(∑_(n = 0)^∞)(((-1))^n) ((x^(2  n))/((2  n)!))

Now graph f[x] and the Maclaurin polynomial s[x] over the interval [-2, 2].

Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -2, 2}, 
        PlotRange -> {{-2, 2}, All}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

The curves are distinct, but this is only evident if we look at them over a larger interval.

Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -(3/2) π, (3/2) π}, 
        PlotRange -> {{-(3/2) π, (3/2) π}, All}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Background for part 2 (b).  Use the fact that the series is "alternating" to investigate the error for the Maclaurin polynomial of degree n = 10 over the interval  [-2.0, 2.0].

Now look closely at the "error" when the series is used to approximate the function. How close are were the two curves in part (a) ?

e[x_] = Simplify[f[x] - s[x]]; 
Plot[f[x] - s[x], {x, -2.0, 2.0}, PlotRange -> All, 
        PlotStyle -> Blue]; 
Print["e[x] = ", e[x] ];

This series is "very nice" because it is alternating, and for that reason the error bound is the magnitude of the "next non-zero term" in the series.

Normal[Series[f[x], {x, 0, 12}] ] -Normal[
        Series[f[x], {x, 0, 10}] ]

errorbound = Abs[ -((x^12)/(12!)) ]

The error bound for the entire interval  [-2.0, 2.0] is

Abs[ ((x^12)/(12!)) ]

N[Abs[ ((x^12)/(12!)) ]]

N[Abs[ ((2^12)/(12!)) ]]

This estimate is "conservative" and is a little larger than the "actual" maximum error which occurred at   x = ±2.0

Print[" e[2.0] = ", e[2.0], "\n", "e[-2.0] = ", 
        e[-2.0] ];

Solution 2 (b).

Background. Lagrange form of the Remainder.  The Lagrange form of the error is  R[x, c] = ((Derivative[21][f][c])/(21!))(x^21)  where  c  is known to exist and lies somewhere between  0  and  x.

Clear[c];
R[x_, c_] = ((Derivative[11][f][c])/(11!))(x^11); 
Print["The Lagrange form of the remainder is", "\n"]; 
Print["R[x,c] = 
(f^((11)))[c]/(11!)(x^11) where c lies somewhere between 0 and x.","\n"]; 
Print["R[x,c] = ", Together[R[x, c]] ];

First we need to bound the size of the term  ((Derivative[11][f][c])/(11!))  for values of  c  in the interval  -2.0 ≤ c ≤ 2.0.  This can easily be done graphically, but to do it analytically with derivatives is quite messy.  We choose to look at the following graph to see what is happening.

Plot[((Derivative[11][f][c])/(11!)),{c, -2.0, 2.0},PlotRange -> All,PlotStyle -> Blue]; 
Print["
(f^((11)))[c]/(11!) = ",Together[((Derivative[11][f][c])/(11!))] ];

How big does  ("\!\(f\^\((21)\)\)[c]"/(11!))  get ?  Looking at the graph we can estimate it to be  |((Derivative[11][f][c])/(11!))|≤(1/(11!))= 2.505210838544172`*^-8.  

That's good enough.

How big does the error  R[x, c] = ((Derivative[11][f][c])/(11!))(x^11)  get ?  Notice that |R[x, c]| = |((Derivative[11][f][c])/(11!))||(x^11)|.  
We will use the bound the first portion|((Derivative[11][f][c])/(11!))|≤ 2.505210838544172`*^-8  and  then bound the portion  |(x^11)|  over the interval  [-2.0, 2.0]  by evaluating it at  x = ±2.0

\(\(\(Print[\*""|(x^11)| ≤ "", \((2.0)\)\^11];\)\(\ \)\)\)

Now multiply the two numbers together to find the error bound for Lagrange's remainder formula. 

	\(\(\(|\)\(R[x, 
            c]\)\(|\)\(\(≤\)\(\ \)\(2.505210838544172`*^-8*2048\)\)\) = \(0.0000513067008`\  = \ 
          5.13067×10\^\(-5\)\)\)  

This is a larger than the actual maximum error we found. Remember is an "error bound."

Print[" e[2.0] = ", e[2.0], "\n", "e[-2.0] = ", 
        e[-2.0] ];

Solution 2 (c).

2 (c).  Find the terms up to  (x^20)  in the Maclaurin series and see how close it approximates  f[x].

Go ahead "enjoy" and add terms in the series up to (x^20), then plot the functions over the interval [-((5 π)/2), ((5  π)/2)].

f[x_] = Cos[x]; 
s[x_] = 
        Normal[Series[f[x], {x, 0, 20}] ]; 
Plot[{f[x], s[x]}, {x, -((5 π)/2), ((5 π)/2)}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Question.  Do we have a "good approximation" on the interval   [-((5 π)/2), ((5  π)/2)]?

f[((5 π)/2)]-s[((5 π)/2)]

N[f[((5 π)/2)] - s[((5  π)/2)]]

Mathematical notation.  Mathematica has adopted the notation  Log[x]  for the natural logarithm.  This can be illustrated by using either differentiation or integration.  Since  Log[x]  starts with the upper case letter  L,  the word  Log  is a "reserved word."

D[Log[x],  x]

∫(1/x) \[DifferentialD]x

Example 3.  Consider the function  f[x] = -Log[1 - x].  
3 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x]. 
3 (b).  Investigate the error in the approximation over the interval [-0.5, 0.5]. 
3 (c).  Find the terms up to  (x^20)  in the Maclaurin series and see how close it approximates  f[x].

Solution 3 (a).

3 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x].

f[x_] = - Log[1 - x]; 
T  =  Series[f[x], {x, 0, 10}]; 
s[x_] = Normal[T]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Remark.  If you just find the "Series" it will include a "Big O"  term, which cannot be used in either evaluations or graphing, we eliminate it with the command "Normal."  The "Big O"  term lets us know the power of x in the "remainder."

Series[f[x], {x, 0, 10}]

Normal[Series[f[x], {x, 0, 10}] ]

Aside.  Of course the "full" Maclaurin series has an infinite number of terms.  Mathematica is capable of finding sums of infinite series.

Clear[n];
Sum[((x^n)/n), {n, 1, Infinity}]

The "symbolic" command is:

(∑_(n = 1)^∞)((x^n)/n)

Use Mathematica to sum the infinite series  (∑_(n = 1)^∞)(((((1/2)))^n)/n). 
Check it out for  x  =  (1/2).

(∑_(n = 
            1)^∞)(((((1/2)))^n)/n)

Check it out for  x  =  2.

(∑_(n = 1)^∞)((2^n)/n)

What is happening to the terms in the last series ?

Limit[((2^n)/n), n -> ∞]

The n-th term does not go to zero, therefore   (∑_(n = 1)^∞) ((2^n)/n)  diverges.

Do we really need to understand the "interval of convergence" ?  What is it ?

Needs["Graphics`Colors`"]; 
gr1 = 
        Plot[f[x], {x, -2, 1}, PlotStyle -> Magenta, 
          DisplayFunction -> Identity]; 
gr2 = 
        Plot[s[x], {x, -2, 2}, PlotStyle -> Green, 
          DisplayFunction -> Identity]; 
Show[gr2, gr1, 
        DisplayFunction -> $DisplayFunction]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

The "interval of convergence" is [-1,1).  Look at what happens in this interval ?

Plot[{f[x], s[x]}, {x, -1, 1}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Aside.  The logarithm of negative numbers is allowed in the study of complex analysis.  For example

Print["Log[-1] = ", 
        Log[-1] ]; 
\(\(Print[\*""(E^Log)[-1] = "", E\^Log[\(-1\)], "
"\ ];\)\ \)
\(\(Print[\*""(E^I)π = "", E\^Iπ];\)\ \)
\(\(Print[\*""(E^I)π+1 = "", E\^Iπ\  + 1];\)\ \)

This leads to one of the most curious equations in mathematics  (e^(i π )) + 1 = 
        0,  because it involves many of our basic numbers  0, 1, i, e, π.  You are welcome to experiment with complex numbers in this course.  For example, Newton's method will converge to those "complex roots" if you give it an initial starting value that is complex and reasonably close to the desired root.

Background for part 3 (b).  Use the fact that the series is "alternating" to investigate the error for the Maclaurin polynomial of degree n = 10 over the interval  [-0.5, 0.5].

Now look closely at the "error" when the series is used to approximate the function.  It becomes infinite near x = 1.  For this reason we work on smaller intervals, in this case we chose  [-0.5, 0.5].  How close are were the two curves in part (a) ?

e[x_] = Simplify[f[x] - s[x]]; 
Plot[f[x] - s[x], {x, -0.5, 0.5}, 
        PlotRange -> {{-0.5, 0.5}, {-0.00003, 0.0001}}, 
        PlotStyle -> Blue]; 
Print["e[x] = ", e[x] ];

Caveat. The series is not alternating and we cannot use the magnitude of the "next term" in the series to determine an error bound.

errorbound = Abs[(( (x^11))/11) ]

The error bound for the entire interval  [-0.5, 0.5] is

Abs[((((0.5))^11)/11) ]

However, the estimate does not work on the interval  [0, 0.5]  where the series is not alternating.

\(\(\(Print[" e[0.5] = ", 
        e[0.5], "
", \*"" e[0.5] ≤ Abs[((((0.5))^11)/11) ] is "", 
        e[0.5] ≤ 
          Abs[\((0.5)\)\^11\/11\ ]\ \ ];\)\(\ \)\)\)

However, the estimate will work on the interval  [-0.5, 0]  where the series is alternating.

\(\(\(Print["e[-0.5] = ", 
        e[\(-0.5\)], "
", \*"" e[-0.5] ≤ Abs[((((0.5))^11)/11) ] is "", 
        e[\(-0.5\)] ≤ 
          Abs[\((0.5)\)\^11\/11\ ]\ \ ];\)\(\ \)\)\)

Solution 3 (b).

Background. Lagrange form of the Remainder.  The Lagrange form of the error is  R[x, c] = ((Derivative[21][f][c])/(21!))(x^21)  where  c  is known to exist and lies somewhere between  0  and  x.

Clear[c];
R[x_, c_] = ((Derivative[11][f][c])/(11!))(x^11); 
Print["The Lagrange form of the remainder is", "\n"]; 
Print["R[x,c] = 
(f^((11)))[c]/(11!)(x^11) where c lies somewhere between 0 and x.","\n"]; 
Print["R[x,c] = ", Together[R[x, c]] ];

First we need to bound the size of the term  ((Derivative[11][f][c])/(11!))  for values of  c  in the interval  -0.5 ≤ c ≤ 0.5.  This can easily be done graphically, but to do it analytically with derivatives is quite messy.  We choose to look at the following graph to see what is happening.

Plot[{0.001051,186.182,((Derivative[11][f][c])/(11!))},{c, -0.5, 0.5},PlotRange -> All,PlotStyle -> {Cyan, Cyan, Blue}]; 
Print["
(f^((11)))[c]/(11!) = ",Together[((Derivative[11][f][c])/(11!))] ];

How big does  ("\!\(f\^\((21)\)\)[c]"/(11!))  get ?  Looking at the graph we can estimate it to be  |((Derivative[11][f][c])/(11!))|≤ 186.1818181818182`.  

That's good enough.

How big does the error  R[x, c] = ((Derivative[11][f][c])/(11!))(x^11)  get ?  Notice that |R[x, c]| = |((Derivative[11][f][c])/(11!))||(x^11)|.  
We will use the bound the first portion|((Derivative[11][f][c])/(11!))|≤ 186.1818181818182`  and  then bound the portion  |(x^11)|  over the interval  [-0.5, 0.5]  by evaluating it at  x = ±0.5

\(\(\(Print[\*""|(x^11)| ≤ "", \((0.5)\)\^11];\)\(\ \)\)\)

Now multiply the two numbers together to find the error bound for Lagrange's remainder formula. 

	\(\(\(|\)\(R[x, 
            c]\)\(|\)\(\(≤\)\(\ \)\(4.88281×10\^\(-4\)*186.182\)\)\) = \(0.09090904436363637`\  = \ 
          9.0909×10\^\(-2\)\)\)  

This is a quite a bit larger than the actual maximum error we found. Remember is an "error bound."

Print[" e[0.5] = ", e[0.5], "\n", "e[-0.5] = ", 
        e[-0.5] ];

Solution 3 (c).

3 (c).  Find the terms up to  (x^20)  in the Maclaurin series and see how close it approximates  f[x].

Go ahead "enjoy" and add terms in the series up to (x^20), then plot the functions over the interval [-2, 2].

Needs["Graphics`Colors`"]; 
s[x_] = 
        Normal[Series[f[x], {x, 0, 20}] ]; 
gr1 = 
        Plot[f[x], {x, -2, 1}, PlotStyle -> Magenta, 
          DisplayFunction -> Identity]; 
gr2 = 
        Plot[s[x], {x, -2, 2}, PlotStyle -> Green, 
          DisplayFunction -> Identity]; 
Show[gr2, gr1, PlotRange -> {{-2, 2}, {-2, 20}}, 
        DisplayFunction -> $DisplayFunction]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Example 4.  Consider the function  f[x] = BesselJ[0, x].  
4 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x]. 
4 (b).  Investigate the error term (Subscript[E, n]) (x)for the Maclaurin polynomial of degree n = 10 over the interval  [-2.0, 2.0].  
4 (c).  Find the terms up to  (x^20)  in the Maclaurin series and see how close it approximates  f[x].

Solution 4 (a).

4 (a).  Find the terms up to  (x^10)  in the Maclaurin series for  f[x].

f[x_] = BesselJ[0, x]; 
T  =  Series[f[x], {x, 0, 10}]; 
s[x_] = Normal[T]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Remark.  If you just find the "Series" it will include a "Big O"  term, which cannot be used in either evaluations or graphing, we eliminate it with the command "Normal."  The "Big O"  term lets us know the power of x in the "remainder."

Series[f[x], {x, 0, 10}]

Normal[Series[f[x], {x, 0, 10}] ]

Aside.  Of course the "full" Maclaurin series has an infinite number of terms.  Mathematica is capable of finding sums of infinite series.  

The following is just for fun !

There are two ways to get infinite sums, the old way and the new way.

Clear[n];
Sum[((((-1))^n)/(((n!))^2)) ((((x/2)))^(2  n)) , {n, 0, 
        Infinity}]

The "symbolic" command is:

(∑_(n = 0)^∞)((((-1))^n)/(((n!))^2)) ((((x/2)))^(2  n))

Now graph f[x] and the Maclaurin polynomial s[x] over the interval [-2, 2].

Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -2, 2}, 
        PlotRange -> {{-2, 2}, {0, 1}}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

The curves are distinct, but this is only evident if we look at them over a larger interval.

Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -5, 5}, 
        PlotRange -> {{-5, 5}, All}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Background for part 4 (b).  Use the fact that the series is "alternating" to investigate the error for the Maclaurin polynomial of degree n = 10 over the interval  [-2.0, 2.0].

Now look closely at the "error" when the series is used to approximate the function. How close are were the two curves in part (a) ?

e[x_] = Simplify[f[x] - s[x]]; 
Plot[f[x] - s[x], {x, -2.0, 2.0}, PlotRange -> All, 
        PlotStyle -> Blue]; 
Print["e[x] = ", e[x] ];

This series is "very nice" because it is alternating, and for that reason the error bound is the magnitude of the "next non-zero term" in the series.

Normal[Series[f[x], {x, 0, 12}] ] -Normal[
        Series[f[x], {x, 0, 10}] ]

errorbound = Abs[ -((x^12)/(12!)) ]

The error bound for the entire interval  [-2.0, 2.0] is

Abs[ ((x^12)/(12!)) ]

N[Abs[ ((x^12)/(12!)) ]]

N[Abs[ ((2^12)/(12!)) ]]

This estimate is "conservative" and is a little larger than the "actual" maximum error which occurred at   x = ±2.0

Print[" e[2.0] = ", e[2.0] , "\n", "e[-2.0] = ", 
        e[-2.0] ];

Solution 4 (b).

Background. Lagrange form of the Remainder.  The Lagrange form of the error is  R[x, c] = ((Derivative[21][f][c])/(21!))(x^21)  where  c  is known to exist and lies somewhere between  0  and  x.

Clear[c];
R[x_, c_] = ((Derivative[11][f][c])/(11!))(x^11); 
Print["The Lagrange form of the remainder is", "\n"]; 
Print["R[x,c] = 
(f^((11)))[c]/(11!)(x^11) where c lies somewhere between 0 and x.","\n"]; 
Print["R[x,c] = ", Together[R[x, c]] ];

First we need to bound the size of the term  ((Derivative[11][f][c])/(11!))  for values of  c  in the interval  -2.0 ≤ c ≤ 2.0.  This can easily be done graphically, but to do it analytically with derivatives is quite messy.  We choose to look at the following graph to see what is happening.

Plot[{-5.86855×(10^(-9)),5.86855×(10^(-9)),((Derivative[11][f][c])/(11!))},{c, -2.0, 2.0},PlotRange -> All,PlotStyle -> {Cyan, Cyan, Blue}]; 
Print["
(f^((11)))[c]/(11!) = ",Together[((Derivative[11][f][c])/(11!))] ];

How big does  ("\!\(f\^\((21)\)\)[c]"/(11!))  get ?  Looking at the graph we can estimate it to be  |((Derivative[11][f][c])/(11!))|≤ 5.868551375136101`*^-9.  

That's good enough.

How big does the error  R[x, c] = ((Derivative[11][f][c])/(11!))(x^11)  get ?  Notice that |R[x, c]| = |((Derivative[11][f][c])/(11!))||(x^11)|.  
We will use the bound the first portion|((Derivative[11][f][c])/(11!))|≤ 2.505210838544172`*^-8  and  then bound the portion  |(x^11)|  over the interval  [-2.0, 2.0]  by evaluating it at  x = ±2.0

\(\(\(Print[\*""|(x^11)| ≤ "", \((2.0)\)\^11];\)\(\ \)\)\)

Now multiply the two numbers together to find the error bound for Lagrange's remainder formula. 

	\(\(\(|\)\(R[x, 
            c]\)\(|\)\(\(≤\)\(\ \)\(5.868551375136101`*^-9*2048\)\)\) = \(0.0000513067008`\  = \ 
          1.20188×10\^\(-5\)\)\)  

This is a larger than the actual maximum error we found. Remember is an "error bound."

Print[" e[2.0] = ", e[2.0] "\n", "e[-2.0] = ", 
        e[-2.0] ];

Solution 4 (c).

4 (c).  Find the terms up to  (x^20)  in the Maclaurin series and see how close it approximates  f[x].

Go ahead "enjoy" and add terms in the series up to (x^20), then plot the functions over the interval [-5 , 5].

f[x_] = BesselJ[0, x]; 
s[x_] = 
        Normal[Series[f[x], {x, 0, 20}] ]; 
Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -5, 5 }, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Question.  Do we have a "good approximation" on the interval   [-5 , 5]?

f[5 ]-s[5 ]

N[f[5 ] - s[5]]

Aside.  Mathematica actually computes the higher derivatives of f[x] up to the order 50 when calculating the Taylor series. Suppose you had to find the formula for the first 20 derivatives of f[x].  Could "you" do it ?  Would you want to do it ?

Warning.  Be sure that you leave the command "Together" in the print statement.  Otherwise the size of the output for the derivatives is 79MB, which might crash your computer.

For[i = 0,i ≤ 20,i++,
Print[Derivative[i]["f"],"[x] = ",Together[Derivative[i][f][x]]] ;];

For[i = 0,i ≤ 20,i++,
Print[Derivative[i]["f"],"[0] = ",Derivative[i][f][0]] ;];

Example 5.  Consider the function  f[x] = (e^(-(x^2)/2)).  
5 (a).  Find the terms up to  (x^20)  in the Maclaurin series for  f[x]. 
5 (b).  Investigate the error term (Subscript[E, n]) (x)for the Maclaurin polynomial of degree n = 20 over the interval  [-2.0, 2.0].  
5 (c).  Find the terms up to  (x^50)  in the Maclaurin series and see how close it approximates  f[x]. 
5 (d).  The relationship to the standard normal distribution.

Solution 5 (a).

5 (a).  Find the terms up to  (x^20)  in the Maclaurin series for  f[x].

f[
          x_] = (E^(-(x^2)/2)); 
T  =  Series[f[x], {x, 0, 20}]; 
s[x_] = Normal[T]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Remark.  If you just find the "Series" it will include a "Big O"  term, which cannot be used in either evaluations or graphing, we eliminate it with the command "Normal."  The "Big O"  term lets us know the power of x in the "remainder."

Series[f[x], {x, 0, 20}]

Normal[Series[f[x], {x, 0, 20}] ]

Aside.  Of course the "full" Maclaurin series has an infinite number of terms.  Mathematica is capable of finding sums of infinite series.  

The following is just for fun !

There are two ways to get infinite sums, the old way and the new way.

Clear[n];
Sum[(((-1))^n) ((x^(2  n))/((2^n) n!)), {n, 0, 
        Infinity}]

The "symbolic" command is:

(∑_(n = 0)^∞)(((-1))^n) ((x^(2  n))/((2^n) n!))

Now graph f[x] and the Maclaurin polynomial s[x] over the interval [-3, 3].

Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -3, 3}, 
        PlotRange -> {{-3, 3}, {0, 1}}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

The above approximation is not too good near the endpoints, this is why we want to graph f[x] and the Maclaurin polynomial s[x] over the interval [-2, 2].

Needs["Graphics`Colors`"]; 
Plot[{f[x], s[x]}, {x, -2, 2}, 
        PlotRange -> {{-2, 2}, {0, 1}}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Background for part 5 (b).  Use the fact that the series is "alternating" to investigate the error for the Maclaurin polynomial of degree n = 20 over the interval  [-2.0, 2.0].

Now look closely at the "error" when the series is used to approximate the function.  How close are were the two curves in part (a) ?

e[x_] = Simplify[f[x] - s[x]]; 
Plot[f[x] - s[x], {x, -2.0, 2.0}, PlotRange -> All, 
        PlotStyle -> Blue]; 
Print["e[x] = ", e[x] ];

This series is "very nice" because it is alternating, and for that reason the error bound is the magnitude of the "next non-zero term" in the series.

Normal[Series[f[x], {x, 0, 22}] ] -Normal[
        Series[f[x], {x, 0, 20}] ]

errorbound = Abs[ -((x^22)/((2^11) 11!)) ]

The error bound for the entire interval  [-2.0, 2.0] is

Abs[ ((2^22)/((2^11) 11!)) ]

N[Abs[ ((2^22)/((2^11) 11!)) ]]

This estimate is "conservative" and is a little larger than the "actual" maximum error which occurred at   x = ±2.0

Print[" e[2.0] = ", e[2.0], "\n", "e[-2.0] = ", 
        e[-2.0] ];

Solution 5 (b).

Background. Lagrange form of the Remainder.  The Lagrange form of the error is  R[x, c] = ((Derivative[21][f][c])/(21!))(x^21)  where  c  is known to exist and lies somewhere between  0  and  x.

Clear[c];
R[x_, c_] = ((Derivative[21][f][c])/(21!))(x^21); 
Print["The Lagrange form of the remainder is", "\n"]; 
Print["R[x,c] = 
(f^((21)))[c]/(21!)(x^21) where c lies somewhere between 0 and x.","\n"]; 
Print["R[x,c] = ", Together[R[x, c]] ];

First we need to bound the size of the term  ((Derivative[21][f][c])/(21!))  for values of  c  in the interval  -2.0 ≤ c ≤ 2.0.  This can easily be done graphically, but to do it analytically with derivatives is quite messy.  We choose to look at the following graph to see what is happening.

Plot[((Derivative[21][f][c])/(21!)),{c, -2.0, 2.0},PlotRange -> All,PlotStyle -> Blue]; 
Print["
(f^((21)))[c]/(21!) = ",Together[((Derivative[21][f][c])/(21!))] ];

How big does  ("\!\(f\^\((21)\)\)[c]"/(21!))  get ?  Looking at the graph we can estimate it to be  |((Derivative[21][f][c])/(21!))|≤ 5.64441×(10^(-11)).  

That's good enough.

How big does the error  R[x, c] = ((Derivative[21][f][c])/(21!))(x^21)  get ?  Notice that |R[x, c]| = |((Derivative[21][f][c])/(21!))||(x^21)|.  
We will use the bound the first portion|((Derivative[21][f][c])/(21!))|≤ 5.64441×(10^(-11))  and  then bound the portion  |(x^21)|  over the interval  [-2.0, 2.0]  by evaluating it at  x = ±2.0

\(\(\(Print[\*""|(x^21)| ≤ "", \((2.0)\)\^21];\)\(\ \)\)\)

Now multiply the two numbers together to find the error bound for Lagrange's remainder formula. 

	\(\(\(|\)\(R[x, 
            c]\)\(|\)\(\(≤\)\(\ \)\(5.64441×10\^\(-11\)*2.097152×10\^6\)\)\) = \(0.00011837185720319999`\  = \ 1.18372×10\^\(-4\)\)\)  

This is a little larger than the actual maximum error we found. Remember is an "error bound."

Print[" e[2.0] = ", e[2.0], "\n", "e[-2.0] = ", 
        e[-2.0] ];

Solution 5 (c).

5 (c).  Find the terms up to  (x^50)  in the Maclaurin series and see how close it approximates  f[x].

Go ahead "enjoy" and add terms in the series up to (x^50), then plot the functions over the interval [-3.0, 3.0].

f[
          x_] = (E^(-(x^2)/2)); 
s[x_] = 
        Normal[Series[f[x], {x, 0, 50}] ]; 
Plot[{f[x], s[x]}, {x, -3.0, 3.0}, 
        PlotStyle -> {Magenta, Green}]; 
Print["f[x] = ", f[x], "\n", "s[x] = ", 
        s[x]];

Question.  Do we have a "good approximation" on the interval  [-3.0, 3.0] ?

f[3]-s[3]

N[f[3] - s[3]]

Aside.  Mathematica actually computes the higher derivatives of f[x] up to the order 50 when calculating the Taylor series. Suppose you had to find the formula for the first 20 derivatives of f[x].  Could "you" do it ?  Would you want to do it ?

For[i = 0,i ≤ 20,i++,
Print[Derivative[i]["f"],"[x] = ",Together[Derivative[i][f][x]]] ;];

For[i = 0,i ≤ 20,i++,
Print[Derivative[i]["f"],"[0] = ",Derivative[i][f][0]] ;];

Solution 5 (d).

The Standard Normal Distribution  Φ[x] is merely a multiple of f[x] = (e^(-(x^2)/2)).

Φ[
          x_]  =  (1/(Sqrt[2 π])) (E^(-(x^2)/2));
Needs["Graphics`Colors`"]; 
Plot[Φ[x], {x, -4, 4}, 
        PlotRange -> {{-4, 4}, {0, 0.4}}, 
        PlotStyle -> {Magenta}]; 
Print["     Φ[x] = ", Φ[
          x] ]; 
\(\(Print[\*""(∫_(-∞)^∞)Φ[x]\[DifferentialD]x = "", ∫\_\(-∞\)\%∞ Φ[x] \[DifferentialD]x\ ];\)\ \)

Various Scenarios and Animations for the Taylor and Maclaurin polynomials.

Example 6.  Find the Taylor polynomial for  f[x] = (Sqrt[x]) expanded about  (Subscript[x, 0]) = 1, (Subscript[x, 0]) = 4, and (Subscript[x, 0]) = 5.

Solution 6 (a).

f[x_] = (Sqrt[x]);  
x0 = 1;  
a = 0; 
b =  10.5; 
c = 0.0; 
d = 3.5; 
a0 = 0.0; 
b0 = 2.0; 
Needs["Graphics`Colors`"]; 
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
For[n = 2, 
      n ≤ 5, n++, 
P[x_]  =  
        Normal[Series[f[x], {x, x0, n}]];   
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[0, 10, 2], Range[0, 4, 1]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; 
Print["\
f[x] = ", f[x], "\n", "P[x] = ", P[x]];  ]

Animation 1.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Solution 6 (b).

f[x_] = (Sqrt[x]);  
x0 = 4;  
a = 0; 
b =  10.5; 
c = 0.0; 
d = 3.5; 
a0 = 0.0; 
b0 = 8.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 
        5, \(n++\), 
P[x_]\  = \ \ Normal[
          Series[f[x], {x, x0, n}]]; \ \ 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[0, 10, 2], Range[0, 4, 1]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 2.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Solution 6 (c).

f[x_] = (Sqrt[x]);  
x0 = 5;  
a = 0; 
b =  10.5; 
c = 0.0; 
d = 3.5; 
a0 = 0.0; 
b0 = 10.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, n}]]; \ \ \ 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[0, 10, 2], Range[0, 4, 1]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 3.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Example 7.  Find the Maclaurin polynomial for  f[x] = (1/(Sqrt[1 - x]))  expanded about  (Subscript[x, 0]) = 0.

Solution 7.

f[x_] = (1/(Sqrt[1 - x]));  
x0 = 0;  
a = -1.5; 
b =  1.5; 
c = 0.0; 
d = 8.5; 
a0 = -1.0; 
b0 = 1.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[\ Series[f[x], {x, x0, n}]]; \ \ 
graph1 = 
        Plot[f[x], {x, \(-1.5\),  .9999}, PlotStyle -> Magenta, 
          DisplayFunction -> Identity]; 
graph2 = 
        Plot[P[x], {x, \(-1.5\), 1.5}, PlotStyle -> Blue, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        graph2, Cdot, Rends, PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-1.5\), 1.5, 0.5], Range[0, 5, 1]}, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 4.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 8.  Find the Maclaurin polynomial for  f[x] = (1/(1  +  (x^2))) expanded about  (Subscript[x, 0]) = 0.

Solution 8.

f[x_] = (1/(1 + (x^2)));  
x0 = 0;  
a = -1.5; 
b =  1.5; 
c = 0.0; 
d = 1.25; 
a0 = -1.0; 
b0 = 1.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 4, 
      n ≤ 7, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, 2  n}]]; \ \ 
graph = 
        Plot[{f[x], P[x]}, {x, \(-1.5\), 1.5}, 
          PlotStyle -> {Magenta, Blue}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-1.5\), 1.5, 0.5], Range[0, 1, 0.5]}, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 5.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 9.  Find the Taylor polynomial for  f[x] = Log[x] expanded about  (Subscript[x, 0]) = 1, and (Subscript[x, 0]) = 2.

Solution 9 (a).

f[x_] = Log[x];  
x0 = 1;  
a = -0.5; 
b =  4.1; 
c = -6.0; 
d = 3.0; 
a0 = 0; 
b0 = 2.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, n}]]; \ \ \ 
graph1 = 
        Plot[{f[x], P[x]}, {x, 0.001, b}, PlotStyle -> {Magenta, Blue}, 
          DisplayFunction -> Identity]; 
graph2 = 
        Plot[P[x], {x, \(-0.5\), b}, PlotStyle -> {Magenta, Blue}, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        graph2, Cdot, Rends, PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-0.5\), 4.0, 0.5], Range[\(-5\), 0, 1]}, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 4.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Solution 9 (b).

f[x_] = Log[x];  
x0 = 2;  
a = -0.5; 
b =  4.1; 
c = -6.0; 
d = 3.0; 
a0 = 0; 
b0 = 4.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, n}]]; \ \ \ 
graph1 = 
        Plot[{f[x], P[x]}, {x, 0.001, b}, PlotStyle -> {Magenta, Blue}, 
          DisplayFunction -> Identity]; 
graph2 = 
        Plot[P[x], {x, \(-0.5\), b}, PlotStyle -> {Magenta, Blue}, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        graph2, Cdot, Rends, PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-0.5\), 4.0, 0.5], Range[\(-6\), 0, 1]}, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 5.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Example 10.  Find the Taylor polynomial for  f[x] = Sin[x] expanded about  (Subscript[x, 0]) = 0, and (Subscript[x, 0]) = (π/4).

Solution 10 (a).

f[x_] = Sin[x];  
x0 = 0;  
a = -3 π; 
b = 3  π; 
c = -1.3; 
d =  1.3; 
a0 = -10; 
b0 = 10; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, 2  n + 1}]]; 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-3\) π, 3  π, π], 
              Range[\(-0.5\), 1, 0.5]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 7.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Solution 10 (b).

f[x_] = Sin[x];  
x0 = (π/4);  
a = (π/4) - 2  π; 
b = (π/4) + 2  π; 
c = -1.3; 
d =  1.3; 
a0 = -10; 
b0 = 10; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = 
        Normal[Series[f[x], {x, x0, n}]]; 
graph1 = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          DisplayFunction -> Identity]; 
r = 
        3.785; \ 
If[
        n > 1, \(r = b;\)]; 
graph2 = 
        Plot[P[x], {x, a, b}, PlotStyle -> Blue, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        Cdot, Rends, PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-3\) π, 3  π, π\/2], 
            Range[\(-0.5\), 1, 0.5]}, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 6.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Example 11.  Find the Taylor polynomial for  f[x] = Cos[x] expanded about  (Subscript[x, 0]) = 0, and (Subscript[x, 0]) = (π/3).

Solution 11 (a).

f[x_] = Cos[x];  
x0 = 0;  
a = -3 π; 
b = 3  π; 
c = -1.3; 
d =  1.3; 
a0 = -10; 
b0 = 10; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, 2  n}]]; 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-3\) π, 3  π, π], 
              Range[\(-0.5\), 1, 0.5]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 8.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Solution 11 (b).

f[x_] = Cos[x];  
x0 = (π/3);  
a = (π/3) - 2  π; 
b = (π/3) + 2  π; 
c = -1.3; 
d =  1.3; 
a0 = -10; 
b0 = 10; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, n}]]; \ \ 
graph1 = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-3\) π, 3  π, π\/2], 
              Range[\(-0.5\), 1, 0.5]}, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 7.  ( Taylor Polynomial  Taylor Polynomial ).  Internet hyperlink.

Example 12.  Find the Maclaurin polynomial for  f[x] = Tan[x] expanded about  (Subscript[x, 0]) = 0.

Solution 12.

f[x_] = Tan[x];  
x0 = 0;  
a = -π; 
b = π; 
c = -10; 
d =  10; 
a0 = ((-π)/2); 
b0 = (π/2); 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = 
        Normal[Series[
            f[x], {x, x0, 2  n + 1}]]; \ \ \ 
graph1 = 
        Plot[f[x], {x, a, \(-π\)\/2}, PlotStyle -> {Magenta}, 
          DisplayFunction -> Identity]; 
graph2 = 
        Plot[f[x], {x, \(-π\)\/2, π\/2}, PlotStyle -> {Magenta}, 
          DisplayFunction -> Identity]; 
graph3 = 
        Plot[f[x], {x, π\/2, b}, PlotStyle -> {Magenta}, 
          DisplayFunction -> Identity]; 
graph4 = 
        Plot[P[x], {x, \(-π\), π}, PlotStyle -> {Blue}, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        graph2, graph3, graph4, Cdot, Rends, 
        PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-π\), π, π\/2], 
            Range[\(-6\), 10, 2]}, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 9.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 13.  Find the Maclaurin polynomial for  f[x] = (e^x) expanded about  (Subscript[x, 0]) = 0.

Solution 13.

f[x_] = (E^x);  
x0 = 0;  
a = -2.0; 
b =  3.0; 
c = -4.0; 
d = 20.5; 
a0 = -5.0; 
b0 = 5.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 1, 
      n ≤ 5, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, n}]]; \ \ 
graph1 = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-2\), 3, 1], Range[0, 20, 5]}, 
          DisplayFunction -> Identity]; 
figure = 
        Show[graph1, Cdot, Rends, 
          DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 10.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 14.  Find the Maclaurin polynomial for  f[x] = Cos[x] (e^(-x)) expanded about  (Subscript[x, 0]) = 0.

Solution 14.

f[x_] = 
        Cos[x] (E^(-x));  
x0 = 0;  
a = -2.0; 
b =  4.0; 
c = -3.5; 
d = 2.0; 
a0 = -3.0; 
b0 = 5.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, n}]]; \ \ 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-2\), 4, 1], Range[\(-2\), 2, 1]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 11.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 15.  Find the Maclaurin polynomial for  f[x] = ArcTan[x] expanded about  (Subscript[x, 0]) = 0.

Solution 15.

f[x_] = ArcTan[x];  
x0 = 0;  
a = -2; 
b =  2; 
c = -1.6; 
d =  1.6; 
a0 = -1; 
b0 = 1; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = \ 
        Normal[Series[
            f[x], {x, x0, 2  n + 1}]]; \ \ 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-1.5\), 1.5, 0.5], 
              Range[\(-π\)\/4, π\/4, π\/4]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 13.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 16.  Find the Maclaurin polynomial for  f[x] = ArcSin[x] expanded about  (Subscript[x, 0]) = 0.

Solution 16.

f[x_] = ArcSin[x];  
x0 = 0;  
a = -1.5; 
b =  1.5; 
c = -2.2; 
d = 2.2; 
a0 = -1.0; 
b0 = 1.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 2, 
      n ≤ 5, \(n++\), 
P[x_]\  = 
        Normal[Series[
            f[x], {x, x0, 2  n + 1}]]; \ \ \ \ 
graph1 = 
        Plot[{f[x], P[x]}, {x, \(-0.9999\), 0.9999}, 
          PlotStyle -> Magenta, 
          DisplayFunction -> Identity]; 
graph2 = 
        Plot[P[x], {x, \(-1.5\), 1.5}, PlotStyle -> Blue, 
          DisplayFunction -> Identity]; 
Show[graph1, 
        graph2, Cdot, Rends, PlotRange -> {{a, b}, {c, d}}, 
        Ticks -> {Range[\(-1.5\), 1.5, 0.5], 
            Range[\(-π\)\/2, π\/2, π\/4]}, 
        DisplayFunction -> $DisplayFunction]; \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 14.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 17.  Find the Maclaurin polynomial for  f[x] = BesselJ[0, x] expanded about  (Subscript[x, 0]) = 0.

Solution 17.

f[x_] = BesselJ[0, x];  
x0 = 0;  
a = -10.2; 
b = 10.2; 
c = -0.8; 
d =  1.3; 
a0 = -11; 
b0 = 11; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, 2  n}]]; 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-10\), 10, 2], Range[\(-0.5\), 1, 0.5]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 15.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 18.  Find the Maclaurin polynomial for  f[x] = (1/(Sqrt[2  π])) (e^(-(x^2)/2)) expanded about  (Subscript[x, 0]) = 0.

Solution 18.

f[
          x_] = (1/(Sqrt[2  π])) (E^(-(x^2)/2));  
x0 = 0;  
a = -3.0; 
b =  3.0; 
c = -0.15; 
d = 0.5; 
a0 = -4.0; 
b0 = 4.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, 2  n}]]; 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-3\), 3, 1], Range[0, 0.4, 0.1]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 17.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Example 19.  Find the Maclaurin polynomial for  f[x] = (1/2)  + (1/2) Erf[(x/(Sqrt[2]))] expanded about  (Subscript[x, 0]) = 0.

Solution 19.

f[x_] = (1/2)  + (1/2) Erf[(x/(Sqrt[2]))];  
x0 = 0;  
a = -3.0; 
b =  3.0; 
c = -0.25; 
d = 1.25; 
a0 = -4. ; 
b0 = 4.0; 
Needs["Graphics`Colors`"];
Cdot = 
        Graphics[{{Red, PointSize[0.02], 
              Point[{x0, f[x0]}]}}]; 
Rends = 
        Graphics[{{Green, Line[{{a0, c}, {a0, d}}]}, {Red, 
              Line[{{x0, c}, {x0, d}}]}, {Green, 
              Line[{{b0, c}, {b0, d}}]}}]; 
\(For[n = 3, 
      n ≤ 6, \(n++\), 
P[x_]\  = \ 
        Normal[Series[f[x], {x, x0, 2  n + 1}]]; 
graph = 
        Plot[{f[x], P[x]}, {x, a, b}, PlotStyle -> {Magenta, Blue}, 
          PlotRange -> {{a, b}, {c, d}}, 
          Ticks -> {Range[\(-3\), 3, 1], Range[0, 0.8, 0.25]}, 
          DisplayFunction -> Identity]; 
Show[graph, 
        Cdot, Rends, 
        DisplayFunction -> $DisplayFunction]; \ \ 
Print["f[x] = ", f[x], "
", "P[x] = ", 
        P[x]];\ \ ]\ \ \)

Animation 18.  ( Maclaurin Polynomial  Maclaurin Polynomial ).  Internet hyperlink.

Animations (Taylor and Maclaurin Polynomial Approximation  Taylor and Maclaurin Polynomial Approximation).  Internet hyperlinks to animations.

Old Lab Project (Maclaurin Polynomials  Maclaurin Polynomials).  Internet hyperlinks to an old lab project.

Old Lab Project (Taylor Polynomials  Taylor Polynomials).  Internet hyperlinks to an old lab project.

Research Experience for Undergraduates

Maclaurin and Taylor Polynomials  Maclaurin and Taylor Polynomials  Internet hyperlinks to web sites and a bibliography of articles.

hornereval[coefflist_List, 
        xval_] := 
 (*coefflist is in order from highest degree to constant*) 
Module[{amat, newb, 
          n}, 
amat = 
          Reverse[coefflist]; 
n = 
          Length[amat]; 
newb = 
          amat; 
Table[
          newb[[k]] = amat[[k]] + xval* newb[[k + 1]], {k, 
            n - 1, 1, -1}]; 
newb[[1]]
]

f[x_] := 3  x^3 - x^2 + 1

hornereval[{3, -1, 0, 1}, 2]

f[x] /. x -> 2

newhornereval[coefflist_List, 
        xval_] := 
  
Module[{a, b, 
          n = Length[coefflist]}, 
Table[
          a[k - 1] = coefflist[[k]], {k, 1, n}]; 
b[
            n - 1] = a[n - 1]; 
For[i = n - 2, 
          i ≥ 0, 
          b[i] = a[i] + b[i + 1]*xval; i--]; 
b[
          0]
]

newhornereval[{1, 0, -1, 3}, 2]

hornerderiv[coefflist_List, 
        xval_] := 
  
Module[{a, d, 
          n = Length[coefflist]}, 
Table[
          a[k - 1] = coefflist[[k]], {k, 1, n}]; 
d[
            n - 2] = (n - 1)*a[n - 1]; 
For[i = n - 2, 
          i ≥ 0, 
          d[i - 1] = i*a[i] + d[i]*xval; i--]; 
d[
          0]
]

hornerderiv[{1, 0, -1, 3}, 2]

D[f[x], x] /. x -> 2

hornerinteg[coefflist_List, 
        xval_] := 
  
Module[{a, integ, 
          n = Length[coefflist]}, 
Table[
          a[k - 1] = coefflist[[k]], {k, 1, n}]; 
integ[
            n] = a[n - 1]/n; 
For[i = n, i > 1, 
          integ[i - 
                1] = (a[i - 2]/(i - 1)) + (integ[i]*
                  x); i--]; 
Expand[
          c + integ[1]*x]
]

hornerinteg[{1, 0, -1, 3}, 2]

Integrate[f[x], x]

Interpolating Polynomial.

Find an interpolation polynomial for the function

f[x_] := (E^(-(x^2)))

where the interpolating polynomial is evaluated at -2,-1, 0,1, and 2

pts = Table[{x, f[x]}, {x, -2, 2, 1}]

g1 = 
        Plot[f[x], {x, -3, 3}, 
          DisplayFunction -> Identity];

g2 = 
        ListPlot[pts, PlotStyle -> PointSize[0.02], 
          DisplayFunction -> Identity];

Show[g1, g2, DisplayFunction -> $DisplayFunction];

poly[x_, n_] := Apply[Plus, Table[a[i] x^i, {i, 0, n}]]

poly[x, 4]

f[-2]

soln = 
      Solve[Table[(poly[x, 4] /. x -> xval) == 
            f[xval], {xval, -2, 2, 1}], {a[0], a[1], a[2], a[3], 
          a[4]}]

a[2] /. soln

g3 = 
        Plot[poly[x, 4] /. soln, {x, -3, 3}, 
          PlotStyle -> RGBColor[1, 0, 0], 
          DisplayFunction -> Identity];

Show[g1, g2, g3, 
        DisplayFunction -> $DisplayFunction];

∫Cos[(t^2)] \[DifferentialD]t

(∫_(-1)^0) Cos[(t^2)] \[DifferentialD]t

N[%]

f[x_] := (∫_(-1)^x) Cos[(t^2)] \[DifferentialD]t

Series[f[x], {x, 0, 5}]