Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

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:

  1. Taylor’s Theorem: Can you write down Taylor’s theorem with the Lagrange form of the remainder? What conditions on ff are required?

  2. Error Analysis: Given a finite difference formula, can you derive its error using Taylor expansions?

  3. Order of Accuracy: What does it mean for a method to be “first-order” or “second-order” accurate? How do you verify this computationally?

  4. Implementation: Can you implement forward and central difference approximations in Python?

  5. 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?

  6. Round-off Error: Why does the error start to increase for very small hh? 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.

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 f(x)=x2x2f(x) = x^2 - x - 2.

Solution

(a) At x0=0x_0 = 0:

  • f(0)=2f(0) = -2, f(0)=1f'(0) = -1, f(0)=2f''(0) = 2, f(0)=0f'''(0) = 0

  • P1(x)=2xP_1(x) = -2 - x

  • P2(x)=2x+x2P_2(x) = -2 - x + x^2

  • P3(x)=2x+x2=f(x)P_3(x) = -2 - x + x^2 = f(x)

P3(x)=f(x)P_3(x) = f(x) because ff is a degree 2 polynomial, and Pn(x)=f(x)P_n(x) = f(x) for all n2n \geq 2.

(b) At x0=2x_0 = 2:

  • f(2)=0f(2) = 0, f(2)=3f'(2) = 3, f(2)=2f''(2) = 2

  • P1(x)=3(x2)P_1(x) = 3(x-2)

  • P2(x)=3(x2)+(x2)2=x2x2=f(x)P_2(x) = 3(x-2) + (x-2)^2 = x^2 - x - 2 = f(x)

(c) For any polynomial ff of degree m\leq m and nmn \geq m: f(x)Pn(x)=0f(x) - P_n(x) = 0.


Q1.3: Taylor Approximation of tan(x)

Find both P2(x)P_2(x) and P3(x)P_3(x) for f(x)=tanxf(x) = \tan x about x0=0x_0 = 0, and use them to approximate tan(0.2)\tan(0.2).

Hint: Plots may be helpful to answer the following questions.

Solution

For f(x)=tanxf(x) = \tan x at x0=0x_0 = 0:

  • f(0)=0f(0) = 0

  • f(x)=sec2xf'(x) = \sec^2 x, so f(0)=1f'(0) = 1

  • f(x)=2sec2xtanxf''(x) = 2\sec^2 x \tan x, so f(0)=0f''(0) = 0

  • f(x)=2sec4x+4sec2xtan2xf'''(x) = 2\sec^4 x + 4\sec^2 x \tan^2 x, so f(0)=2f'''(0) = 2

Therefore:

  • P2(x)=xP_2(x) = x

  • P3(x)=x+x33P_3(x) = x + \frac{x^3}{3}

Approximations: P2(0.2)=0.2P_2(0.2) = 0.2, P3(0.2)=0.2027P_3(0.2) = 0.2027

The true value is tan(0.2)0.2027\tan(0.2) \approx 0.2027, so P3P_3 is much more accurate.


Finite Difference Exercises


Q1.4: Central Difference Analysis

Consider the central finite difference scheme to approximate f(x0)f'(x_0):

f(x0)f(x0+h)f(x0h)2hf'(x_0) \approx \frac{f(x_0 + h) - f(x_0 - h)}{2h}
Solution

(a) From the derivation in the notes: q=2q = 2 and C=112(f(ξ+)+f(ξ))C = \frac{1}{12}(f'''(\xi^+) + f'''(\xi^-)).

(b) The log-log plot should show slope 2 for moderate values of hh. For very small hh, round-off error dominates and the error increases.


Q1.5: Second Derivative Approximation

Given a function f(x)f(x), use Taylor’s theorem to derive a second-order approximation of f(x0)f''(x_0).

Hint: Your finite difference approximation for f(x0)f''(x_0) should include the terms f(x0±h)f(x_0 \pm h) and f(x0)f(x_0).

Solution

The second derivative approximation is:

f(x0)f(x0+h)2f(x0)+f(x0h)h2f''(x_0) \approx \frac{f(x_0 + h) - 2f(x_0) + f(x_0 - h)}{h^2}

The error is E(h)=h212f(4)(ξ)E(h) = -\frac{h^2}{12}f^{(4)}(\xi) for some ξ\xi near x0x_0.

This is a second-order method (O(h2)\mathcal{O}(h^2)).


Q1.6: One-Sided Second-Order Approximation

Given a function f(x)f(x), use Taylor approximations to derive a second-order (i.e., the error should be E(h)=Ch2E(h) = Ch^2) approximation to f(x0)f'(x_0).

Hint: Your approximation should include the terms f(x0)f(x_0), f(x0+h)f(x_0 + h), and f(x0+2h)f(x_0 + 2h).

Hint

Expand f(x0+h)f(x_0 + h) and f(x0+2h)f(x_0 + 2h) in Taylor series, then find coefficients a,b,ca, b, c such that:

af(x0)+bf(x0+h)+cf(x0+2h)=f(x0)+O(h2)af(x_0) + bf(x_0 + h) + cf(x_0 + 2h) = f'(x_0) + \mathcal{O}(h^2)
Solution

The formula is:

f(x0)3f(x0)+4f(x0+h)f(x0+2h)2hf'(x_0) \approx \frac{-3f(x_0) + 4f(x_0+h) - f(x_0+2h)}{2h}

This is useful when you can only sample to one side of x0x_0 (e.g., at a boundary).


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.

Solution for (f)

At x=0x = 0: tanx=x+x33+2x515+\tan x = x + \frac{x^3}{3} + \frac{2x^5}{15} + \cdots

At x=π/4x = \pi/4: tanx=1+2(xπ/4)+2(xπ/4)2+\tan x = 1 + 2(x - \pi/4) + 2(x - \pi/4)^2 + \cdots

At x=π/2x = \pi/2: No Taylor series exists because tan(x)\tan(x) has a vertical asymptote at x=π/2x = \pi/2 (it is not continuous there, let alone differentiable).