Question: Taylor Series Python Assignment The N th order Taylor series formula is: f ( x + h ) ~~ f ( x ) + h
Taylor Series Python Assignment
The th order Taylor series formula is:
~~dots
where denotes the th derivative of the function at the point
The error in the formula will be less than the Taylor error bound, which is given by:
Warmup exercise:
Complete the following code that computes and plots the th order Taylor series approximation and Taylor error bound for with expansion point
on the interval with increment
### Import section
# necessary statements for numerical plotting in Jupyter
import numpy as np
import matplotlib.pyplot as plt
matplotlib inline
# Factorial comes from 'math' package
from math import factorial
### Initialization section
#array of derivatives at compute by hand
deriv nparray
# degree of Taylor polynomial
Nlenderiv
# Max abs value of N deriv on interval Compute using calculus
# used in the remainder formula
# @@@ The N derivative will be proportional to cosine, and cos is always
# @@@ less than
maxAbsNplusderiv
#array with h values
h nparange
# Give the expansion point for the Taylor series
expansion
# Create an array to contain Taylor series
taylor npzeroslenh
### Calculation section
#calculate Taylor series for all h at once using a loop
for n in rangeN:
taylor taylor hnfactorialnderivn
#actual function values
actualFn npcosexpansionh
#error actual and taylor series
actualAbsError abstayloractualFn
#theoretical max errorhdegdegmaxn deriv
theoAbsError abshNfactorialNmaxAbsNplusderiv
#Compute actual x values displaced by expansion point
xActual expansionh
### Output section
#plot figures for cos and errors using objectoriented style
# Two subplots in a row
fig, axes pltsubplotsnrows ncols figsize
# objects for the left subplot attached to axes #
axesplotxActual taylor, rlabel'Taylor series'
axesplotxActual actualFn, b label'cosx
axeslegendloc#legend in upper left
axessettitleTaylor Series for cosx
# objects for the right subplot attached to axes #
axesplotxActual actualAbsError,label'Actual Absolute Error'
axesplotxActual theoAbsError, label'Theoretical Max Absolute Error'
axeslegendloc#legend in upper left
axessettitleActual and Theoretical Max Errors'Exercises
Copy your code into another cell, and modify to plot the th order Taylor series approximation and theoretical max error of with
expansion point on the interval with increment
NOTES
ith order' means that you use up to the th derivatives so the series has terms
ii Since the expansion point is not zero, in your graph you will need to plot on the xaxis versus the Taylor series value on the axis.
iii. When calculating the theoretical max error, use the fact that the absolute value of the sine function is always less than same is true for the cosine
function So everywhere that the sine function appears in your remainder expression, you may replace with
PLEASE HELP ME WITH EX AND USE PYTHON
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
