Polynomial Approximations

One way to approximate a function f[x] by a polynomial p[x] is to solve for the coefficients of p[x] that will make the graph of p[x] pass through a given set of points on the graph of f[x]. For example, let us find a third degree polynomial p[x] which has the same values as Cos[x] for x == -Pi, 0, Pi, and 2Pi.

pc  =  Plot[Cos[x],  {x, -2 Pi, 3  Pi}]

p[x_]  =  a x^3  +  b x^2  +  c x  +  d;

eqns  = 
       {p[-Pi]  == Cos[-Pi],  p[0]  ==  Cos[0],  
        p[Pi]  ==  Cos[Pi],  p[2  Pi]  ==  Cos[2  Pi]}

soln  =  Solve[eqns] // First

p[x_]  =  p[x]  /.  soln

p3  =  Plot[p[x],  {x, -2 Pi, 3  Pi}]

Show[pc, p3]

The results are disappointing. The polynomial does go through the specified set of points, but the shape of its graph does not correspond well to the shape of Cos[x]. A better approach that also takes into account the shape of the graph is to find a polynomial that has the same value and derivatives as Cos[x] at one point, say x==0.

q[x_]  =  a x^3  +  b x^2  +  c x  +  d;

eqns1  = 
       {q[0]  ==  Cos[0],  q'[0]  ==  Cos'[0],  
        q''[0]  ==  Cos''[0],  
        q'''[0]  ==  Cos'''[0]}

soln1  =  Solve[eqns1] // First

q[x_]  =  q[x]  /.  soln1

pq  =  
      Plot[q[x],  {x, -Pi,  3  Pi},  PlotRange -> {-4, 1}]

Show[pc, pq]

This technique can be applied to find a polynomial of any degree n that approximates any function f[x] as long as the function has n derivatives at 0. The coefficients of the polynomial, called the n-th degree Taylor polynomial and denoted by T[f,n], that can easily be determined in advance and give rise to the formula:

T[f_, n_]  :=  
      Sum[ (D[f, {x, k}] /. {x -> 0} )/k! x^k,  {k, 0, n}]

(The term (D[f,{x,k}]/.{x->0} )/k! stands for the k-th derivative of f at 0 devided by k!.)

T[Cos[x], 3]

T[Cos[x], 15]

p15  =  Plot[%, {x, -3 Pi, 3  Pi}]

Show[pc, p15]

The graphs shows that the higher the degree n, the better the approximation.