Practice applying Taylor’s theorem and implementing finite difference methods. These exercises build both theoretical understanding and computational skills.
Self-Assessment Questions¶
Test your understanding with these conceptual questions:
Taylor’s Theorem: Can you write down Taylor’s theorem with the Lagrange form of the remainder? What conditions on are required?
Error Analysis: Given a finite difference formula, can you derive its error using Taylor expansions?
Order of Accuracy: What does it mean for a method to be “first-order” or “second-order” accurate? How do you verify this computationally?
Implementation: Can you implement forward and central difference approximations in Python?
Log-Log Plots: Why do we use log-log plots to verify convergence rates? What slope should you expect for first-order and second-order methods?
Round-off Error: Why does the error start to increase for very small ? What is the optimal step size for forward differences with double precision?
Computational Exercises¶
Q1.1: Taylor Series Visualization¶
Consider the program taylor.py or the equivalent Jupyter notebook posted on Moodle.
(a) Setup your computer so that you can execute either program.
(b) Create a plot showing the first four Taylor series expansions of :
Use a different color for each line.
Plot NumPy’s exponential function in dashed black.
Make sure your name appears in the plot title.
Put the absolute error of the approximation of for each graph in the plot’s legend. Use two significant figures and scientific notation.
Hint
Use np.exp(x) for the exact function. For Taylor polynomials, you can compute them iteratively by adding terms.
Q1.2: Taylor Polynomials of Quadratics¶
Consider the polynomial .
(a) Find , and for centered at . What is the relation between and ? Why?
(b) Find , and for centered at . What is the relation between and ? Why?
(c) In general, given a polynomial with degree , what can you say about for ?
Solution
(a) At :
, , ,
because is a degree 2 polynomial, and for all .
(b) At :
, ,
(c) For any polynomial of degree and : .
Q1.3: Taylor Approximation of tan(x)¶
Find both and for about , and use them to approximate .
Hint: Plots may be helpful to answer the following questions.
(a) Show that in each case the remainder term provides an upper bound for the true error.
(b) Using the remainder term, find a minimum value of for to approximate to within on .
Solution
For at :
, so
, so
, so
Therefore:
Approximations: ,
The true value is , so is much more accurate.
Finite Difference Exercises¶
Q1.4: Central Difference Analysis¶
Consider the central finite difference scheme to approximate :
(a) Show that the approximation error is , where and are constants that you will determine.
(b) Consider the function at . Develop a function that approximates using the central difference scheme. Using that function, create a log-log plot of the absolute error against the step size for , . Also plot the function . Does the slope of this line match the slope of the absolute error? Explain what you observe.
Solution
(a) From the derivation in the notes: and .
(b) The log-log plot should show slope 2 for moderate values of . For very small , round-off error dominates and the error increases.
Q1.5: Second Derivative Approximation¶
Given a function , use Taylor’s theorem to derive a second-order approximation of .
Hint: Your finite difference approximation for should include the terms and .
(a) What is the precise form of the error term?
(b) Create the following plots, and for each explain what you observe:
Plot the value against the discretization size .
Plot the absolute error vs. the discretization size .
Plot the absolute error divided by vs. the discretization size . Verify that the values converge to the value derived from the error term.
Solution
The second derivative approximation is:
The error is for some near .
This is a second-order method ().
Q1.6: One-Sided Second-Order Approximation¶
Given a function , use Taylor approximations to derive a second-order (i.e., the error should be ) approximation to .
Hint: Your approximation should include the terms , , and .
(a) What is the precise form of the error term?
(b) Using your formula, approximate where for , . Create:
A semilog plot of against .
A log-log plot of the absolute error vs. .
A plot of the absolute error divided by vs. .
Hint
Expand and in Taylor series, then find coefficients such that:
Solution
Taylor Series Practice¶
Q1.7: Computing Taylor Series¶
Compute Taylor series for the following functions. Report the first three nonzero terms and show your work.
(a) at (for )
(b) at (for )
(c) at
(d) at
(e) at
(f) at . Can you compute a Taylor series near ? Why or why not?
Solution for (f)
At :
At :
At : No Taylor series exists because has a vertical asymptote at (it is not continuous there, let alone differentiable).