Challenge

Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method

Derivation of 4th-Order Approximations for the Second-Order Derivative

We approximate the second derivative using Taylor series expansions.

1. Central Difference Scheme (CDS)

Using the Taylor series expansions:

f(x+h)=f(x)+hf′(x)+h22f′′(x)+h36f′′′(x)+h424f′′′′(x)+O(h5)f(x+h) = f(x) + h f'(x) + \frac{h^2}{2} f''(x) + \frac{h^3}{6} f'''(x) + \frac{h^4}{24} f''''(x) + O(h^5) f(x−h)=f(x)−hf′(x)+h22f′′(x)−h36f′′′(x)+h424f′′′′(x)+O(h5)f(x-h) = f(x) - h f'(x) + \frac{h^2}{2} f''(x) - \frac{h^3}{6} f'''(x) + \frac{h^4}{24} f''''(x) + O(h^5)

Adding these two expansions:

f(x+h)+f(x−h)=2f(x)+h2f′′(x)+h412f′′′′(x)+O(h6)f(x+h) + f(x-h) = 2f(x) + h^2 f''(x) + \frac{h^4}{12} f''''(x) + O(h^6)

Dividing by h2h^2:

f′′(x)≈−f(x+2h)+16f(x+h)−30f(x)+16f(x−h)−f(x−2h)12h2f''(x) \approx \frac{-f(x+2h) + 16f(x+h) - 30f(x) + 16f(x-h) - f(x-2h)}{12h^2}

2. Right-Skewed Difference Scheme

Expanding f(x)f(x) in a right-skewed form:

f(x+h)=f(x)+hf′(x)+h22f′′(x)+h36f′′′(x)+h424f′′′′(x)+O(h5)f(x+h) = f(x) + h f'(x) + \frac{h^2}{2} f''(x) + \frac{h^3}{6} f'''(x) + \frac{h^4}{24} f''''(x) + O(h^5) f(x+2h)=f(x)+2hf′(x)+4h22f′′(x)+8h36f′′′(x)+16h424f′′′′(x)+O(h5)f(x+2h) = f(x) + 2h f'(x) + \frac{4h^2}{2} f''(x) + \frac{8h^3}{6} f'''(x) + \frac{16h^4}{24} f''''(x) + O(h^5) f(x+3h)=f(x)+3hf′(x)+9h22f′′(x)+27h36f′′′(x)+81h424f′′′′(x)+O(h5)f(x+3h) = f(x) + 3h f'(x) + \frac{9h^2}{2} f''(x) + \frac{27h^3}{6} f'''(x) + \frac{81h^4}{24} f''''(x) + O(h^5) f(x+4h)=f(x)+4hf′(x)+16h22f′′(x)+64h36f′′′(x)+256h424f′′′′(x)+O(h5)f(x+4h) = f(x) + 4h f'(x) + \frac{16h^2}{2} f''(x) + \frac{64h^3}{6} f'''(x) + \frac{256h^4}{24} f''''(x) + O(h^5)

Using a weighted sum to cancel odd-order derivatives:

f′′(x)≈−f(x+4h)+4f(x+3h)−5f(x+2h)+2f(x+h)h2f''(x) \approx \frac{-f(x+4h) + 4f(x+3h) - 5f(x+2h) + 2f(x+h)}{h^2}

3. Left-Skewed Difference Scheme

Similarly, expanding terms in a left-skewed manner:

f(x−h),f(x−2h),f(x−3h),f(x−4h)f(x-h), f(x-2h), f(x-3h), f(x-4h)

Following a similar weighted sum approach:

f′′(x)≈−f(x−4h)+4f(x−3h)−5f(x−2h)+2f(x−h)h2f''(x) \approx \frac{-f(x-4h) + 4f(x-3h) - 5f(x-2h) + 2f(x-h)}{h^2}


MATLAB Code for Numerical Approximation

This code computes the second derivative using all three numerical schemes and compares their accuracy with the analytical derivative.

Why Are Skewed Schemes Useful?

Skewed schemes are particularly useful when:

  • The function is defined only on one side (e.g., near a boundary).
  • The domain has a discontinuity or a singularity at one end.
  • We are solving a problem with a flow direction (e.g., upwind schemes in fluid dynamics).

What Skewed Schemes Can Do That Central Difference Cannot?

  • They allow accurate differentiation at boundaries where central difference is not feasible.
  • They can be used in non-uniform grids where symmetry is not possible.
  • In computational fluid dynamics (CFD), they help approximate derivatives near walls without requiring ghost points.

% MATLAB script to compute second-order derivatives using different schemes

% Define function and its analytical second derivative

f = @(x) exp(x) .* cos(x);

f_dd_exact = @(x) -2 * exp(x) .* sin(x);

% Define grid

x = linspace(0, pi, 100); % Define range

h = 0.1; % Step size

% Compute numerical second derivatives using different schemes

f_dd_central = (-f(x+2*h) + 16*f(x+h) - 30*f(x) + 16*f(x-h) - f(x-2*h)) / (12*h^2);

f_dd_right = (-f(x+4*h) + 4*f(x+3*h) - 5*f(x+2*h) + 2*f(x+h)) / h^2;

f_dd_left = (-f(x-4*h) + 4*f(x-3*h) - 5*f(x-2*h) + 2*f(x-h)) / h^2;

% Compute absolute errors

error_central = abs(f_dd_central - f_dd_exact(x));

error_right = abs(f_dd_right - f_dd_exact(x));

error_left = abs(f_dd_left - f_dd_exact(x));

% Plot absolute errors

figure;

plot(x, error_central, 'r', 'LineWidth', 2);

hold on;

plot(x, error_right, 'g', 'LineWidth', 2);

plot(x, error_left, 'b', 'LineWidth', 2);

hold off;

title('Absolute Error Comparison of Numerical Schemes');

xlabel('x');

ylabel('Absolute Error');

legend({'Central Difference', 'Right Skewed', 'Left Skewed'});

grid on;

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.