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:
Adding these two expansions:
Dividing by :
2. Right-Skewed Difference Scheme
Expanding in a right-skewed form:
Using a weighted sum to cancel odd-order derivatives:
3. Left-Skewed Difference Scheme
Similarly, expanding terms in a left-skewed manner:
Following a similar weighted sum approach:
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;