Approximating Polynomials
system:sage


<link type="text/css" rel="stylesheet" href="approxpoly.css" /><div class="maketitle">
                                                                                                
                                                                                                
                                                                                                
                                                                                                

<h2 class="titleHead">Approximating Polynomials</h2>
     <div class="author"><span class="cmr-12x-x-120">Robert A.</span><span class="cmr-12x-x-120">&#160;Beezer</span>
<br/><span class="cmr-12x-x-120">University of Puget Sound</span></div><br/>
<div class="date"><span class="cmr-12x-x-120">February 20, 2010</span></div>
   </div><h3 class="likesectionHead"><a id="x1-1000"/>Introduction</h3><p class="noindent">This is a short introduction to the notion of using polynomials to approximate more complicated
functions. It is entirely informal, with the intent of motivating a careful study of in&#64257;nite series prior to
learning about Taylor polynomials and Taylor series.
</p><h3 class="sectionHead"><span class="titlemark">1   </span> <a id="x1-20001"/>A Very Basic Approximating Polynomial</h3><p class="noindent">Consider the following algebra centering on polynomial multiplication,
</p><div class="math">\eqalignno{
        (1 &#8722; x)(1 + x + {x}^{2} + {x}^{3} +\cdots  +{x}^{n})        &amp; = 1 + x + {x}^{2} + {x}^{3} +\cdots  +{x}^{n}                             &amp;        &amp;
        \cr 
                                      &amp;\quad \quad  &#8722; (x + {x}^{2} + {x}^{3} +\cdots  +{x}^{n} + {x}^{n+1})                        &amp;        &amp;
        \cr 
                                      &amp; = 1 + (x &#8722; x) + ({x}^{2} &#8722; {x}^{2}) +\cdots  +({x}^{n} &#8722; {x}^{n}) &#8722; {x}^{n+1}        &amp;        &amp;
        \cr 
                                      &amp; = 1 &#8722; {x}^{n+1}                                           &amp;        &amp;
        \cr 
                                      &amp;\approx 1                                                     &amp;        &amp;
   }</div><p class="noindent">The approximation in the last step is valid if <!--l. 72--><span class="math">{x}^{n+1}</span>
is small, which will be the case if <!--l. 72--><span class="math"> &#8722; 1 &lt; x &lt; 1</span>
and <!--l. 72--><span class="math">n</span> is
large. Keep those conditions in mind as we continue.
</p><p class="indent">   If we assume <!--l. 74--><span class="math">x\mathrel{&#8800;}1</span> and divide
both sides of the above by <!--l. 74--><span class="math">1 &#8722; x</span>
we obtain
</p><div class="math">\eqalignno{
                                   {1\over 
1 &#8722; x}                                &amp;\approx 1 + x + {x}^{2} + {x}^{3} +\cdots  +{x}^{n}                                                                &amp;\text{(1)}
   }</div><a id="x1-2001r1"/><p class="noindent">This will be the basis of all but one of our approximations. In the demonstration below notice the
following: </p><ul class="itemize1">
      <li class="itemize">The approximation gets better as the degree, <!--l. 83--><span class="math">n</span>,
      increases.
      </li>
      <li class="itemize">No matter how large the degree is, the approximation appears limited to <!--l. 84--><span class="math"> &#8722; 1 &lt; x &lt; 1</span>.
      </li>
      <li class="itemize">For even versus odd degrees, the left end of the approximating polynomial approaches <!--l. 85--><span class="math">\pm \infty </span>.
      </li>
      <li class="itemize">The degree 1 approximation is just the tangent line at the point <!--l. 86--><span class="math">(0, 1)</span>.</li></ul>

{{{id=1|
%hide
%auto
a=-1.25
b= 0.95
original_color='blue'
approx_color='red'
@interact
                                                                                                
                                                                                                
def _( n = slider(0, 20, 1, 2 , label = "Degree") ):
     var('x')
     f(x)=1/(1-x)
     approx(x)=0
     for i in srange(n+1):
         approx(x)=approx(x)+x^i
     original_plot = plot( f(x), a, b ,color=original_color)
     approx_plot = plot( approx(x),  a, b, color=approx_color)
     html("Function: <font color='%s'>$%s$</font>$" % (original_color, latex(f(x))) )
     html("Approximation: <font color='%s'>$%s$</font>$" % (approx_color, latex(approx(x))) )
     show(original_plot+approx_plot, xmin=a, xmax=b, ymin=0, ymax=10)
///
}}}

<p class="noindent">
</p><h3 class="sectionHead"><span class="titlemark">2   </span> <a id="x1-30002"/>Approximating a Rational Function</h3><p class="noindent">We can use the approximation above to create an approximation of a rational function (a fraction of two
polynomials). With a systematic use of partial fractions, this method can be extended to more complicated
examples. Consider the following:
</p><div class="math">\eqalignno{
                                   {1 + {x}^{2}\over 
1 &#8722; {x}^{2}}                                    &amp; = {1 &#8722; {x}^{2}\over  
1 &#8722; {x}^{2}} +   {2{x}^{2}\over  
1 &#8722; {x}^{2}}                                    &amp;                                   &amp;
                                   \cr 
                                          &amp; = 1 + 2{x}^{2}     {1\over  
1 &#8722; {x}^{2}}                                      &amp;                                   &amp;
                                   \cr 
                                          &amp;                                                      &amp;
   }</div><p class="noindent">Employ equation&#160;(<a href="#x1-2001r1">1<!--tex4ht:ref: geometric --></a>) where we replace <!--l. 124--><span class="math">x</span>
by <!--l. 124--><span class="math">{x}^{2}</span>,
                                                                                                
                                                                                                
</p><div class="math">\eqalignno{
                                                    &amp;\approx 1 + 2{x}^{2}\left (1 + {x}^{2} + {({x}^{2})}^{2} + {({x}^{2})}^{3} +\cdots  +{({x}^{2})}^{n}\right )                          &amp;                          &amp;
                          \cr 
                          &amp; = 1 + 2{x}^{2}\left (1 + {x}^{2} + {x}^{4} + {x}^{6} +\cdots  +{x}^{2n}\right )                              &amp;                          &amp;
                          \cr 
                          &amp; = 1 + 2{x}^{2} + 2{x}^{4} + 2{x}^{6} + 2{x}^{8} +\cdots  +2{x}^{2n+2}                          &amp;                          &amp;
   }</div><p class="noindent">Notice that our approximation should again be best when
<!--l. 132--><span class="math">n</span> is large and now we
would require <!--l. 132--><span class="math"> &#8722; 1 &lt; {x}^{2} &lt; 1</span> which
simply translates back to <!--l. 132--><span class="math"> &#8722; 1 &lt; x &lt; 1</span>.
In the demonstration below we only plot the function for
<!--l. 132--><span class="math"> &#8722; 1 &lt; x &lt; 1</span>. The full graph would
have vertical asymptotes at <!--l. 132--><span class="math">x = &#8722;1</span>
and <!--l. 132--><span class="math">x = 1</span> and has two
branches below the <!--l. 132--><span class="math">x</span>-axis
&#8212; one for <!--l. 132--><span class="math">x &lt; &#8722;1</span> and
another for <!--l. 132--><span class="math">x &gt; 1</span>. </p>

{{{id=3|
%hide
%auto
a=-0.9999
b= 0.9999
original_color='blue'
approx_color='red'
@interact
def _( n = slider(0, 20, 2, 2 , label = "Degree") ):
     var('x')
     f(x)=(1+x^2)/(1-x^2)
     approx(x)=1
     for i in srange(2,n+1,2):
         approx(x)=approx(x)+2*x^i
     original_plot = plot( f(x), a, b ,color=original_color)
     approx_plot = plot( approx(x),  a, b, color=approx_color)
     html("Function: <font color='%s'>$%s$</font>$" % (original_color, latex(f(x))) )
     html("Approximation: <font color='%s'>$%s$</font>$" % (approx_color, latex(approx(x))) )
     show(original_plot+approx_plot, xmin=a, xmax=b, ymin=0, ymax=10)
///
}}}

<p class="noindent">
</p><h3 class="sectionHead"><span class="titlemark">3   </span> <a id="x1-40003"/>Approximating a Transcendental Function</h3><p class="noindent">We begin with equation&#160;(<a href="#x1-2001r1">1<!--tex4ht:ref: geometric --></a>), replacing <!--l. 158--><span class="math">x</span>
by <!--l. 158--><span class="math"> &#8722; {t}^{2}</span>,
then form a de&#64257;nite integral that equals the inverse tangent. Again, we would expect larger values of
<!--l. 158--><span class="math">n</span>, with
<!--l. 158--><span class="math"> &#8722; 1 &lt; x &lt; 1</span>, to
yield better approximations. First,
</p><div class="math">\eqalignno{
                           {1\over 
1 + {t}^{2}}                        &amp; =       {1\over  
1 &#8722; (&#8722;{t}^{2})}                                                 &amp;                        &amp;
                        \cr 
                              &amp;\approx 1 + (&#8722;{t}^{2}) + {(&#8722;{t}^{2})}^{2} + {(&#8722;{t}^{2})}^{3} +\cdots  +{(&#8722;{t}^{2})}^{n}                        &amp;                        &amp;
                        \cr 
                              &amp; = 1 &#8722; {t}^{2} + {t}^{4} &#8722; {t}^{6} +\cdots  +{(&#8722;1)}^{n}{t}^{2n}                               &amp;                        &amp;
   }</div><p class="noindent">We will now use a de&#64257;nite integral and the derivative of the inverse tangent in a novel way,
</p><div class="math">\eqalignno{
                        \arctan (x)                        &amp; =\arctan  (x) &#8722;\arctan  (0)                                                 &amp;                        &amp;
                        \cr 
                           &amp; {=\int }_{ 0}^{x}    {1\over 
1 + {t}^{2}}dt                                                &amp;                        &amp;
                        \cr 
                           &amp;{\approx \int }_{0}^{x}\kern 1.95872pt 1 &#8722; {t}^{2} + {t}^{4} &#8722; {t}^{6} +\cdots  +{(&#8722;1)}^{n}{t}^{2n}\kern 1.95872pt dt                              &amp;                        &amp;
                        \cr 
                           &amp; ={ \left .t &#8722;{{t}^{3}\over  
 3} + {{t}^{5}\over  
 5} &#8722;{{t}^{7}\over  
 7} +\cdots  +{{(&#8722;1)}^{n}{t}^{2n+1}\over 
    2n + 1}   \kern 1.95872pt \right \vert }_{0}^{x}                        &amp;                        &amp;
                        \cr 
                           &amp; = x &#8722;{{x}^{3}\over  
 3}  + {{x}^{5}\over  
 5}  &#8722;{{x}^{7}\over  
 7}  +\cdots  +{{(&#8722;1)}^{n}{x}^{2n+1}\over 
    2n + 1}                           &amp;                        &amp;
   }</div><p class="noindent">In the demonstration below we have drawn attention to the value of the function and the approximating
polynomial at <!--l. 178--><span class="math">x = 1</span>.
It is of course debatable if the approximation is even valid at
<!--l. 178--><span class="math">x = 1</span>, but
we will examine this question carefully later. We know that in a 45-45-90 right triangle, the
two non-hypotenuse sides are equal. Expressing angles in radians we formulate this fact as
<!--l. 178--><span class="math">\tan \left ( {\pi \over 4}\right ) = 1</span>, or equivalently,
<!--l. 178--><span class="math">\arctan (1) =  {\pi \over  4}</span>. So if we evaluate our approximating
polynomial at <!--l. 178--><span class="math">x = 1</span> we should get a
reasonable approximation of <!--l. 178--><span class="math"> {\pi \over 4}</span>,
and by extension, multiplying by 4 we could obtain an estimate of
<!--l. 178--><span class="math">\pi </span>. Consider
that <!--l. 178--><span class="math">\pi </span> is
de&#64257;ned as the ratio of a circle&#8217;s circumfrence to its diameter. Could we derive the necessary trigonometric
facts, limits, derivatives and integrals used above without ever computing an actual value for
<!--l. 178--><span class="math">\pi </span>? I think so. Hmmmmmmmmm.
The &#8220;real&#8221; value of <!--l. 178--><span class="math"> {\pi \over 4}</span>,
and the approximation, are given below, in addition to being pinpointed by speci&#64257;c points on the plot. </p>

{{{id=5|
%hide
%auto
a=-1.75
b= 1.75
original_color='blue'
approx_color='red'
pi_true = point((1, float(pi/4)), rgbcolor='black', pointsize=20)
@interact
def _( n = slider(1, 21, 2, 1 , label = "Degree") ):
     var('x')
     f(x)=arctan(x)
     approx(x)=0
     sign=1
     for i in srange(1,n+1,2):
         approx(x)=approx(x)+sign*x^i/i
         sign=-1*sign
     pi_approx = point( (1, float(approx(1))), rgbcolor='green', pointsize=20)
     original_plot = plot( f(x), a, b ,color=original_color)
     approx_plot = plot( approx(x),  a, b, color=approx_color)
     html("Function: <font color='%s'>$%s$</font>$" % (original_color, latex(f(x))) )
     html("Approximation: <font color='%s'>$%s$</font>$" % (approx_color, latex(approx(x))) )
     print
     html("<font color='%s'>$\\frac{\\pi}{4}=\\arctan(1)=%s$</font>" % (original_color, latex(float(pi/4))) )
     html("<font color='%s'>$P_{%s}(1)=%s$</font>" % (approx_color, latex(n), latex(float(approx(1)))) )
     show(original_plot+approx_plot+pi_true+pi_approx, xmin=a, xmax=b, ymin=-1.5, ymax=1.5)
///
}}}

<p class="noindent">
</p><h3 class="sectionHead"><span class="titlemark">4   </span> <a id="x1-50004"/>An Approximation Valid Everywhere</h3><p class="noindent">Our previous approximating polynomials were each valid, at best, on the interval
<!--l. 211--><span class="math"> &#8722; 1 &lt; x &lt; 1</span>. We will change our
approach for this &#64257;nal example by simply producing a very interesting polynomial and examining its properties. Recall that
&#8220;<!--l. 211--><span class="math">n</span>-factorial&#8221; is de&#64257;ned
by <!--l. 211--><span class="math">n! = n(n &#8722; 1)(n &#8722; 2)\cdots 3\cdot 2\cdot 1</span>, and by convention
<!--l. 211--><span class="math">0! = 1</span>. Consider the polynomials,
indexed by their degree <!--l. 211--><span class="math">n</span>,
</p><div class="math">\eqalignno{
                             {P}_{n}(x)                             &amp; = 1 + x + {{x}^{2}\over  
2!} + {{x}^{3}\over  
3!} + {{x}^{4}\over  
4!} +\cdots  +{{x}^{n}\over 
n!}                             &amp;                             &amp;
   }</div><p class="noindent">Each of these polynomials has a derivative, which we will compute. (Notice how fractions with factorials
simplify nicely.)
</p><div class="math">\eqalignno{
                       {P}_{n}'(x)                       &amp; =  {d\over  
dx}\left (1 + x + {{x}^{2}\over  
2!} + {{x}^{3}\over  
3!} + {{x}^{4}\over  
4!} +\cdots  +{{x}^{n}\over 
n!} \right )                              &amp;                       &amp;
                       \cr 
                             &amp; = 0 + 1 + {2x\over  
2!} + {3{x}^{2}\over  
 3!}  + {4{x}^{3}\over  
 4!}  +\cdots  +{n{x}^{n&#8722;1}\over 
    n!}                               &amp;                       &amp;
                       \cr 
                             &amp; = 1 +  {2x\over  
2(1!)} +  {3{x}^{2}\over  
3(2!)} +  {4{x}^{3}\over  
4(3!)} +\cdots  +    {n{x}^{n&#8722;1}\over 
n((n &#8722; 1)!)}                       &amp;                       &amp;
                       \cr 
                             &amp; = 1 + x + {{x}^{2}\over  
2!} + {{x}^{3}\over  
3!} +\cdots  +  {{x}^{n&#8722;1}\over 
(n &#8722; 1)!}                                   &amp;                       &amp;
   }</div><p class="noindent">So <!--l. 228--><span class="math">{P}_{n}(x)</span> and its derivative,
<!--l. 228--><span class="math">{P}_{n}'(x)</span>, are very similar,
di&#64256;ering only in the term <!--l. 228--><span class="math">{{x}^{n}\over 
n!} </span>.
</p><div class="math">\eqalignno{
                                      {P}_{n}(x) &#8722; {P}_{n}'(x)                                      &amp; = {{x}^{n}\over  
n!}                                       &amp;                                      &amp;
   }</div><p class="noindent">Even for &#64257;xed values of <!--l. 234--><span class="math">x</span>
greater than 1, if we let <!--l. 234--><span class="math">n</span>
get large enough, the denominator of this fraction will overwhelm the numerator, and this di&#64256;erence will be small and
tend to zero. So <!--l. 234--><span class="math">{P}_{n}(x)</span>
is very nearly equal to its derivative. Do we know any functions like this? Ah, yes,
<!--l. 234--><span class="math">{e}^{x}</span>! The demonstration
below examines the possibility that these polynomials might be good approximations to the exponential function. </p>

{{{id=7|
%hide
%auto
a=-2
b= 5
original_color='blue'
approx_color='red'
@interact
def _( n = slider(0, 10, 1, 2 , label = "Degree") ):
     var('x')
     f(x)=e^x
     approx(x)=0
     for i in srange(n+1):
         approx(x)=approx(x)+x^i/factorial(i)
     original_plot = plot( f(x), a, b ,color=original_color)
     approx_plot = plot( approx(x),  a, b, color=approx_color)
     html("Function: <font color='%s'>$%s$</font>$" % (original_color, latex(f(x))) )
     html("Approximation: <font color='%s'>$%s$</font>$" % (approx_color, latex(approx(x))) )
     show(original_plot+approx_plot, xmin=a, xmax=b, ymin=0, ymax=100)
///
}}}