The Taylor series is a mathematical tool that, sometimes, it is not easy to immediately grasp by freshman students. In this blog, I will give a short review of it giving some examples of applications.

**Who is Mr. Taylor?**

Brook Taylor (1685 – 1731) was a 17th-century British mathematician. He demonstrated the celebrated Taylor formula, the topics of this blog, in his masterwork *Methodus Incrementorum Directa et Inversa* (1715). For more information, just give a read to the following wiki page.

### The Taylor Theorem

Let *k* ≥ 1 be an integer and let the function *f* : **R** → **R** be *k* times differentiable at the point *a* ∈ **R**. Then there exists a function *h _{k}* :

**R**→

**R**such that

The polynomial in the series is called *k*-th order Taylor polynomial:

The difference of the series with respect the funzion $f(x) is given by the relation

which gives the error in the approximation of with the Taylor polynomial. Using the little-o notation, the statement in Taylor’s theorem reads as

.

## The MacLaurin Series

The work developed by Taylor was promtly adopted by the Scottish mathematician Colin MacLaurin (1698–1746) that used Taylor series to characterize maxima, minima, and points of inflection for infinitely differentiable functions in his *Treatise of Fluxions*. For his contributions to the development of this important mathematical tool, when the general expression given is used with . the series is also called *Maclaurin series.*

### An example: the cos(x) expansion

The MacLaurin series for the function is given by the expression:

.

In the following panels the expansion for k=1, 2, 3, 6 and 10 terms are reported (see appendix for the program). The function is shown in red, the series in black and the difference in blue colour.

### Some examples of MacLaurin series

Some of commonly used Maclaurin series include:

,

You can use the program in the Appendix I to graphically explore the MacLaurin series of some these function

## Multivariate Taylor Series

The Taylor series can be easily generalized to the multivariate functions. For example let consider the , *k* times differentiable at the point The Taylor expansion for *k=3 *is given by

### An example

Let see as an example the function

The fourth order Taylor series is given by

In the case of the MacLaurin series so that for the above expansion reduce to

In Figure 2, the function and its second order approximation approximation is shown.

*Grapher.*

In Figure 3, the MacLaurin surface including also the 4th order approximation terms is shown. Note that the third order expansion does not contribute to the series since all the third order partial derivatives calculated at (0,0) are equal to zero.

**APPENDIX**

**A program to explore MacLaurin series ****of functions in one variable**

The following program in TCL/TK language allows to calculates and compares the first terms of a MacLaurin series of some transcendent functions.

```
[code language="bash"]
#! /bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# root is the parent window for this user interface
package require Tk
wm title . ""
tk_setPalette cyan3
# Define some variables
# this treats "." as a special case
set root "."
set base ""
set maxX 500
set maxY 500
set width 0
set height 0
set midX 0
set midY 0
set rmin -1.0
set rmax 1.0
set ymax 5.
set ymin -5.
set np 500
set nt 1
set lfuncts "exp(x)"
# Define global variables
global nt width height dcc lfuncts maxX maxY
#############################################################################
## Procedures
# Some of the procedure are adapted from: http://wiki.tcl.tk/15073
#
#############################################################################
proc fact n {expr {$n<2? 1: $n * [fact [incr n -1]]}}
proc ClrCanvas {w } {
global dcc
global rmin rmax width height ymax ymin midX midY
$w delete "all"
set dcc 0
DrawAxis $w
}
proc DrawAxis {w} {
global rmin rmax width height ymax ymin midX midY maxX maxY
set midX [expr { $maxX / 2 }]
set midY [expr { $maxY / 2 }]
set incrX [expr { ($maxX -50) /10 }]
set incrY [expr { $maxY /11 }]
# puts "$midX $midY"
$w create line 0 $midY $width $midY -tags "Xaxis" -fill black -width 1
$w create line $midX 0 $midX $height -tags "Yaxis" -fill black -width 1
$w create text [expr $midX-20] 20 -text "Y"
$w create text [expr $width-20] [expr $midY+20] -text "X"
}
proc DrawFn w {
#
# Plot the sunflover florets
#
global cc np nt
global rmin rmax width height ymax ymin midX midY lfuncts maxX maxY
ClrCanvas .cv
# puts "$lfuncts"
if {$lfuncts == "exp(x)"} {
set rmin -1.0
set rmax 1.0
set ymax 5.
set ymin -5.
} else {
set rmin -3.1415*2
set rmax 3.1415*2
set ymax 1.
set ymin -1.
}
if {$lfuncts == "sinh(x)"} {
set rmin -3.1415/2
set rmax 3.1415/2
set ymax 3.
set ymin -3.
}
set divy [expr ($ymax-$ymin)/$maxY ]
set divx [expr ($rmax-$rmin)/$maxX ]
set asp_ratio 1.
set x $rmin
DrawAxis $w
for { set n 1 } { $n <= $np } { incr n 1 } {
set x [expr $x+$divx]
set xp [expr $midX+ $x/$divx]
if {$lfuncts == "exp(x)"} {
set y [expr exp($x)]
set ys 1.0
for { set m 1} {$m <= $nt} { incr m 1} {
set ys [expr $ys + pow($x,$m)/([fact $m])]
}
}
if {$lfuncts == "sin(x)"} {
set y [expr sin($x)]
set ys 0
for { set m 0} {$m <= $nt} { incr m 1} {
set kk [expr 2*$m+1]
set sign [expr pow(-1,$m)]
set ys [expr $ys + $sign*pow($x,$kk)/([fact $kk])]
}
}
if {$lfuncts == "cos(x)"} {
set y [expr cos($x)]
set ys 1
for { set m 1} {$m <= $nt} { incr m 1} {
set kk [expr 2*$m]
set sign [expr pow(-1,$m)]
set ys [expr $ys + $sign*pow($x,$kk)/([fact $kk])]
}
}
if {$lfuncts == "atan(x)"} {
set y [expr atan($x)]
set ys 0
for { set m 0} {$m <= $nt} { incr m 1} {
set kk [expr 2*$m+1]
set sign [expr pow(-1,$m)]
set ys [expr $ys + $sign*pow($x,$kk)/($kk)]
}
}
if {$lfuncts == "sinh(x)"} {
set y [expr sinh($x)]
set ys 0
for { set m 0} {$m <= $nt} { incr m 1} {
set kk [expr 2*$m+1]
set ys [expr $ys + pow($x,$kk)/($kk)]
}
}
set r [expr $y-$ys]
set yp [expr $midY- $y/$divy*$asp_ratio]
set ysp [expr $midY- $ys/$divy*$asp_ratio]
set re [expr $midY- $r/$divy*$asp_ratio]
if {$n > 1} {
.cv create line $x0 $y1 $xp $yp -tags "Exact" -fill red -width 2
.cv create line $x0 $y2 $xp $ysp -tags "approx" -fill black -width 1
.cv create line $x0 $y3 $xp $re -tags "resid" -fill blue -width 1
}
set y1 $yp
set y2 $ysp
set y3 $re
set x0 $xp
}
}
###############################################################################################
#
# Main with the setup up of the GUI
###############################################################################################
# Row 1
label $base.label#12 \
-background magenta -padx 64 -relief raised -text {MacLaurin Series Calculator (c) Danilo Roccatano 2002-2018}
# Row 2
label $base.label#1 -background green -relief groove -text "Functions: "
ttk::combobox $base.functions -textvariable lfuncts
.functions configure -values [list exp(x) sin(x) cos(x) atan(x) sinh(x)]
# row 3
label $base.terms -background cyan -relief groove -text "Number of terms:" -bg cyan
entry $base.nt -cursor {} -textvariable nt -bg white
# row 5
canvas $base.cv -bg white -height $maxY -width $maxX
# row 6
button $base.plot -text PLOT -command { DrawFn .cv }
button $base.b0 -text "Clear" -command { ClrCanvas .cv }
button $base.b1 -text "EXIT" -command { exit -1}
text $base.t -width 50 -height 5 -wrap word -bg gray90
.t insert end "Select the function and the number of terms of its MacLaurin expansion.\n
The function is plotted in red, the approximation in black and the residual in blue lines."
#
# Add contents to grid
#
# Row 1
grid $base.label#12 -in $root -row 1 -column 1 -columnspan 4 -sticky nesw
# Row 2
grid $base.label#1 -in $root -row 2 -column 1 -sticky nesw
grid $base.functions -in $root -row 2 -column 2 -sticky nesw
grid $base.terms -in $root -row 4 -column 1 -sticky nesw
grid $base.nt -in $root -row 4 -column 2 -sticky nesw
# Row 9 (Canvas)
grid $base.cv -in $root -row 5 -column 1 -columnspan 4 -sticky nesw
# Row 10
grid $base.t -in $root -row 6 -column 1 -columnspan 4 -sticky nesw
grid $base.b0 -in $root -row 7 -column 1
grid $base.plot -in $root -row 7 -column 2
grid $base.b1 -in $root -row 7 -column 4
# additional interface code
bind $base.nt <Return> {DrawFn .cv }
update
# end additional interface code
set width [winfo width .cv ]
set height [winfo height .cv ]
DrawFn .cv
[/code]
```

Pingback: La Serie di Taylor | Danilo Roccatano

Pingback: Calculus in a Nutshell: functions and derivatives | Danilo Roccatano