Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
To derive the the fourth order approximation of the second order derivative using central difference and skewed difference scheme, Starts by defining the Taylor Expansion for the function `f(x)` and its derivatives at a point `x`.
1. Central DifferenceUsing Tayloe expansions, the central difference approximation for the second order derivative `f''(x)` at a point `x` can be derived as follows:
`f''(x) ~~ (1/(trianglex^2))[f(x-trianglex)-2f(x)+f(x+triangle x)]`
To achieve fourth order accuracy, we need to retain terms upto `O(trianglex^4)` in the Taylor expansions.
2. Skewed Right Side Difference
For the skewed right side difference, we need to shift the stencil to the right by `trianglex). The approximation can be derived similarly:
`f''(x) ~~ (1/(trianglex^2))[-f(x-2trianglex)+4f(x-trianglex)-3f(x)]`
3. Skewed Left Sided Difference
Similarly, for the skewed left sided difference, we shifted the dtencil to the left bt `trianglex`
`f''(x) ~~ (1/trianglex^2)[-3f(x) + 4f(x+trianglex)-f(x+2trianglex)]`
Now, Let's prove that these skewew schemes are indeed fourth order accurate using the given hint;
Using the given hint, the order of accuracy `P` for a one sided skewed scheme is given by;
`P = N - Q`
For the fourth order accurate scheme, `P=4`, and for a second order derivative, `Q=2`, So we have `N=6` for skewed schemes and hence it is proved.
Now lets write the MATLAB code to evaluate the second order derivative of the analytical function `f(x) = exp(x) dot cos(x)` and compare it with the central difference and skewed difference scheme.
We can plot the absolute error to visualize the comparison.
%% Initialization
clc
close all
clear all
%% Function to be Evaluated
f = @(x) exp(x) .* cos(x);
%% Analytical Second Derivative
f_double_prime_exact = @(x) -2*exp(x).*sin(x);
%% Define x
x = pi/3;
%% Define dx values
dx_values = linspace(0.001, 0.1, 100); % Adjust range as needed
%% Initialize arrays to store errors
central_error = zeros(size(dx_values));
skewed_right_error = zeros(size(dx_values));
skewed_left_error = zeros(size(dx_values));
%% Loop through different dx values
for j = 1:length(dx_values)
dx = dx_values(j);
%% Central Difference Scheme
central_approx = (f(x + dx) - 2*f(x) + f(x - dx)) / dx^2;
central_error(j) = abs(central_approx - f_double_prime_exact(x));
%% Skewed Right-Sided Difference Scheme
skewed_right_approx = (-f(x - 2*dx) + 4*f(x - dx) - 3*f(x)) / dx^2;
skewed_right_error(j) = abs(skewed_right_approx - f_double_prime_exact(x));
%% Skewed Left-Sided Difference Scheme
skewed_left_approx = (-3*f(x) + 4*f(x + dx) - f(x + 2*dx)) / dx^2;
skewed_left_error(j) = abs(skewed_left_approx - f_double_prime_exact(x));
end
%% Plotting
figure;
loglog(dx_values, central_error, '-o', 'linewidth', 3, 'DisplayName', 'Central Difference');
hold on;
loglog(dx_values, skewed_right_error, '-o', 'linewidth', 3, 'DisplayName', 'Skewed Right-Sided');
loglog(dx_values, skewed_left_error, '-o', 'linewidth', 3, 'DisplayName', 'Skewed Left-Sided');
xlabel('dx');
ylabel('Absolute Error');
legend('Location', 'Best');
title('Comparison of Absolute Errors for Second-Order Derivative Approximations');
grid on;

Comparision Of Absolut Error

Description of the Skewed Scheme Usefulness
Skewed schemes are useful because;
- They cab achieve higher irder accuracy for numerical approximations of deivatives compared to cebtral difference scheme.
- Skewed schemes can be capture asymmetries or directional variations in the function better than central difference schemes.
- They allow for more flexibility in choosing the stencil or neighbourhood points, potentially leading to improved accuracy in specific scenarios.
Difference Between Skewed And Central Difference Schemes
A skewed scheme can capture directional variations in the function, as it shifts the stencil asymmetrically around the point of interest. This allows it to effectively handle situations where the function varies more in one direction than the other. In contrast, cnetral difference schemes are symmetric and may not capture directional variations as accuracy.
Conclusion
The MATLAB results highights the superiority of skewed difference schemes in archieving higher accuracy and fourth order convergence fot approximation the second order derivative comaperd to central difference schemes. This underscores the practical utility and effectiveness of skewed schemes in numerical differentiation applications.