Project Help Notebook by Keith Stroyan

Help NoteBook Copyright 1998 by Academic Press, Inc. - All rights reserved.
Modify this Notebook to prepare your project report.

Project 22: Taylor's Approximations

by A. Student and B. Pupil

with technical help from Da LabMonitor and Help Notebook

Initialization

Needs["Graphics`Colors`"]
powerGraphs[f_,  radius_, numterms_, opns___Rule] :=
	Module[ {functions, graylevels, i, j,n,x,terms},
	Do[
	functions = Table[Normal[Series[f[x],{x,0,n}]], {n, 0, i}] ;
	AppendTo[functions, f[x]] ;
	graylevels = Table[{GrayLevel[j]}, {j, 6/10, 0, -6/(10 i)}] ; 
	graylevels=AppendTo[graylevels,{AbsoluteThickness[2],Red}];
	Plot[Release[functions], {x, -radius, radius},
		PlotStyle -> graylevels, PlotLabel ->i"terms",
		opns,AspectRatio->Automatic];
	,{i, 1, numterms}];
	Do[
	Plot[Release[{Normal[Series[f[x],{x,0,n}]],f[x]}],{x, -radius, radius},
		PlotLabel ->n"terms ", opns, 
		PlotStyle -> {{GrayLevel[0]},{AbsoluteThickness[2],Red}},AspectRatio->Automatic];
	,{n, 1, numterms}];
	];
On[General::spell1];

My Project Introduction

Write this last.  Begin with the basic question and state your main finding clearly, but with few technical details.  You might even modify the title of this section to make it more interesting.

Beginning Explorations or Computer Experiments

This project is mostly paper and pencil work, but following are some computations to help.

Taylor's Formula for n=1: The Microscope Approximation

Review the idea of Zooming as in the Zoom program of Chapter 4.

\(Clear[x, f, dx]; 
f[x_] = \(2  x\)\/\(1 + x\^4\)\)dy  =  Simplify[f'[x]] dx\(x = 1; 


    comparisonCurves[scale_] := 
      Plot[{f[x + dx] - f[x], dy}, {dx, \(-scale\), scale}, 
        AspectRatio -> Automatic, 
        PlotStyle -> {{AbsoluteThickness[3], Red}, Blue}, 
        AxesLabel -> {dx, dy}]; 

    Show[GraphicsArray[{
comparisonCurves[4], 
comparisonCurves[1], 

          comparisonCurves[1/4], 
comparisonCurves[1/16]}]]; \)

Taylor's Formula for n=5: Comparison for Sine

Read Hint 22.2

\(Clear[x, f, dx]; 
f[x_] = Sin[x]\)\(f[n_, x_] := Evaluate[D[f[x], {x, n}]]; 
x = 0; 

    dy\  = \ \(f'\)[x]\ dx\)d3y  =  
      f'[x] dx  +  f''[x]/2 (dx^2) + 
        f[3, x]/(3*2) dx^3d5y  =  
      f'[x] dx  +  f''[x]/2 (dx^2) + 
        f[3, x]/(3*2) dx^3  +  f[4, x]/(4*3*2) dx^4  +  
        f[5, x]/(5*4*3*2) dx^5\(scale = 2; 

    Plot[{f[x + dx] - f[x], dy}, {dx, \(-scale\), scale}, 
      AspectRatio -> Automatic, 
      PlotStyle -> {{AbsoluteThickness[3], Red}, Blue}, 
      AxesLabel -> {dx, dy}]; 

    Plot[{f[x + dx] - f[x], dy, d3y}, {dx, \(-scale\), scale}, 
      AspectRatio -> Automatic, 
      PlotStyle -> {{AbsoluteThickness[3], Red}, Blue, Brown}, 
      AxesLabel -> {dx, dy}]; 

    Plot[{f[x + dx] - f[x], dy, d3y, d5y}, {dx, \(-scale\), scale}, 
      AspectRatio -> Automatic, 
      PlotStyle -> {{AbsoluteThickness[3], Red}, Blue, Brown, Green}, 
      AxesLabel -> {dx, dy}]; \)

You might want to look at this comparison at a larger scale or modify it to compare more terms.

Mathematica's Series[.] Function

Mathematica has a built-in Taylor Series function that uses a change of variables.  Rather than

f[x + dx] = f[x] + f'[x] dx + (1/2)f''[x] (dx^2) + ⋯ + (1/(n!)) (f^((n)))[x] (dx^n)+ ε[x, dx] (dx^n)

we may let  x = a be the fixed value and replace dx with  (x-a).  Thne we get the expression computed in the following input cell.

\(Clear[x, f]; 
numberOfTerms = 9; 

    Series[f[x], {x, a, numberOfTerms}]\)

When  a = 0, we get the special case computed in the next cell.

\(a = 0; 
Series[f[x], {x, a, numberOfTerms}]\)

The Cosine Series

This example gives a general formula for the power series of the Cosine function, displays the first 10 powers and compares it with the built-in computation of the power series expansion of Cosine.

f[x_] = Cos[x]Series[f[x], {x, a, numberOfTerms}]

Now try the graphical comparison with the built-in Series[.]

\(Clear[f, x, a, numberOfTerms]; 
f[x_]\  = \ Cos[x]\)\(a\  = \ 0; 
numberOfTerms = 9; 
radius = 10; 

    powerGraphs[f, radius, numberOfTerms, AspectRatio -> 1\/2, 
      PlotRange -> {\(-2\), 2}]; 

    Series[f[x], {x, 0, numberOfTerms}]\)

Bending and The Second-Order Approximation

Read the project and work through Hint 22.6.  Type your work here.

Increased First-Order Accuracy: Symmetric Differences

Solve Hint 22.7 showing why the symmetric difference gives a better approximation to the tangent line.

\(Clear[f, x, dx, δx, δy]; 

    δy := Fit[points, {1, dx}, dx]; 
f[x_] = Sin[x]\)\(x = π/3; 
δx = π/6; 

    points = {{\(-δx\), f[x - δx]}, {δx, 
          f[x + δx]}}
\)\(curve = 
      Plot[{f[x + dx], f[x] + \(f'\)[x] dx, δy}, {dx, \(-2\), 2}, 
        AspectRatio -> Automatic, 
        PlotStyle -> {{AbsoluteThickness[3], Red}, Blue, Orange}, 
        DisplayFunction -> Identity]; 

    Show[curve, Graphics[{AbsolutePointSize[5], Map[Point, points]}], 
      DisplayFunction -> $DisplayFunction]; 
δy\)N[f[x] + f'[x] dx]

\(δx = π/12; 

    points = {{\(-δx\), f[x - δx]}, {δx, 
          f[x + δx]}}\)δy = Fit[points, {1, dx}, dx]\(curve = 
      Plot[{f[x + dx], f[x] + \(f'\)[x] dx, δy}, {dx, \(-2\), 2}, 
        AspectRatio -> Automatic, 
        PlotStyle -> {{AbsoluteThickness[3], Red}, Blue, Orange}, 
        DisplayFunction -> Identity]; 

    Show[curve, Graphics[{AbsolutePointSize[5], Map[Point, points]}], 
      DisplayFunction -> $DisplayFunction]; \)

A Numerical Comparison

\(Clear[dx]; 
δx = π/24; 

    points = {{\(-δx\), f[x - δx]}, {δx, 
          f[x + δx]}}\)δyN[f'[x]]N[(((f[x + δx] - f[x]))/δ)x]

Second-Order Approximation & Quadratic Fits

Work Hints 22.8, 9 and compare your work with the following Mathematica computations.

\(Clear[f, x, dx, δx, δ2y]; 

    δ2y := Fit[points, {1, dx, dx\^2}, dx]; 
f[x_] = Sin[x]\)\(x = π/3; 
δx = π/6; 

    points = {{\(-δx\), f[x - δx]}, {0, f[x]}, {δx, 
          f[x + δx]}}
\)\(curve = 
      Plot[{f[x + dx], f[x] + \(f'\)[x] dx + \(1\/2\) \(\(f'\)'\)[x]\ dx\^2, 
          δ2y}, {dx, \(-2\), 2}, AspectRatio -> Automatic, 
        PlotStyle -> {{AbsoluteThickness[3], Red}, Blue, Orange}, 
        DisplayFunction -> Identity]; 

    Show[curve, Graphics[{AbsolutePointSize[5], Map[Point, points]}], 
      DisplayFunction -> $DisplayFunction]; 
δ2y\)N[f[x] + f'[x] dx + (1/2) f''[x] (dx^2)]

A Close-by Quadratic Numerical Comparison

\(Clear[dx]; 
δx = π/24; 

    points = {{\(-δx\), f[x - δx]}, {0, f[x]}, {δx, 
          f[x + δx]}}\)δ2yN[f[x] + f'[x] dx + (1/2) f''[x] (dx^2)]

Second Differences and Second Derivatives

Work Hint 22.10

Higher-Order Fits and Local Approximation (Optional)