Skip to content

MANE 3351

Lecture 7

Classroom Management

Agenda

  • Taylor Series Expansion
  • Homework 2
  • Schedule
  • Lab session at 3:30

Resources

Handouts

Assignments


Schedule

Lecture/Lab Date Topic
7 9/20 Taylor Series, Homework 2 (due 9/25 - no late work), Lab 3 (due 9/25)
8 9/23 Roots of Equations, bisection method (not on Test 1)
9 9/25 Bisection Method Error Analysis, False Position (not on Test 1)
10 9/30 Test 1 (lectures 1-7)

Lecture Content

  • Taylor Series Expansion

Taylor Series

Introduction to Taylor Series

Cheney and Kincaid [^1] provide some commonly used Taylor series.

Taylor Series


Example

To find \(e^8\), recall \(e^x=\sum_{k=0}^\infty\frac{x^k}{k!}\)

  1. \(e^8=1\)
  2. \(e^8=1+x=1+8\)
  3. \(e^8=1+8+\frac{x^2}{2!}=1+8+\frac{64}{2}\)
  4. \(e^8=1+8+\frac{64}{2}+\frac{x^3}{3!}=1+8+\frac{64}{2}+\frac{512}{6}\)

Python Code for Jupyter Notebook

import math
import numpy as np
import matplotlib.pyplot as plt
def eTaylor(x,k):
    y=0.0
    for i in range(k):
        #print(i)
        y=y+(x**i)/math.factorial(i)   
        #print("i=",i," y=",y," i!= ",math.factorial(i)," x^i=",x**i)
    return y
k=np.arange(21)
print(k)
print(k[0])
y=0.0*k
for i in np.nditer(k):
    #print(i)
    y[i]=eTaylor(8,i)
#print(y)
#plotting code
fig, ax = plt.subplots()
ax.plot(k, y)
ax.set(xlabel='k', ylabel='e^8(k)',
       title='Taylor Series Approximation')
plt.show()

Taylor Series Expansion about a Point

Taylor Series Polynomial

Source: textbook, page 14


Error Analysis of Taylor Series

  • Note that \(f(x)=T_n(x)+R_n(x)\)
  • Absolute error is \(|f(x)-T_n(x)|=|R_n(x)|\)
  • Absolute error depends on three factors:
    • \(|x-x_0|^{n+1}\)
    • \(\frac{1}{(n+1)!}\)
    • \(|f^{(n+1)}(\xi)|\)
  • An error bound can be found by finding an upper bound on \(|f^{(n+1)}(\xi)|\).

Error Analysis for Exponential Example

# Cell 3
# error analysis of Taylor Series approximation of e^8
# assumes cell two has been run
er=0.0*k
for i in np.nditer(k):
    er[i]=math.exp(8)-y[i]
fig, ax = plt.subplots()
ax.plot(k, er)
ax.set(xlabel='k', ylabel='error',
       title='Taylor Series Approximation')
plt.show()

Error for sine

# cell 4
# Demonstration of T1, T2 and T3 for sine
def T1(x):
    return x
def T2(x):
    return x - x**3/6.0
def T3(u):
    return T2(u)+u**5/120.0
x=np.linspace(-math.pi,math.pi,101)
t1=0.0*x
t2=0.0*x
t3=0.0*x
sin_x=0.0*x
for i in range(0,len(x)):
    t1[i]=T1(x[i])
    t2[i]=T2(x[i])
    t3[i]=T3(x[i])
    sin_x[i]=math.sin(x[i])
fig, ax = plt.subplots()
ax.plot(x, sin_x,label="sine(x)")
ax.plot(x,t1,label="T1")
ax.plot(x,t2,label="T2")
ax.plot(x,t3,label="T3")
ax.set(xlabel='x', ylabel='f(x)',
       title='Taylor Series Approximation of sine')
ax.legend()
plt.show()

Derivative Calculator


[1]: Cheney and Kincaid (2004), Numerical Mathematics and Computing, 5th edition.