Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
Derivation of Central Difference, Skewed Right-Sided Difference, Skewed Left-Sided Difference :



The unknown values of each method obtained using Matlab are:

After getting the unknowns, the same Matlab script which was used to find the unknowns was appended to find out the absolute error between the given three methods
close all
clear all
clc
%Central Scheme
A = [ 1 1 1 1 1;
-2 -1 0 1 2;
2 1/2 0 1/2 2;
-4/3 -1/6 0 1/6 4/3;
2/3 1/24 0 1/24 2/3];
B = [0;0;1;0;0];
C = inv(A)*B
%Right skewed
M = [1 1 1 1 1 1;
0 1 2 3 4 5;
0 1/2 4/2 9/2 16/2 25/2;
0 1/6 8/6 27/6 64/6 125/6;
0 1/24 16/24 81/24 256/24 625/24;
0 1/120 32/120 243/120 1024/120 3125/120];
N = [0;0;1;0;0;0];
R = inv(M)*N
%left skewed
X = [ 1 1 1 1 1 1;
-5 -4 -3 -2 -1 0;
25/2 16/2 9/2 4/2 1/2 0;
-125/6 -64/6 -27/6 -8/6 -1/6 0;
625/24 256/24 81/24 16/24 1/24 0;
-3125/120 -1024/120 -243/120 -32/120 -1/120 0;];
Y = [0;0;1;0;0;0];
L = inv(X)*Y
%Given Function = exp(x)*cos(x)
x=pi/3;
dx=linspace(pi/4,pi/4000,20);
Analytical_Second_Derivative = -2*exp(x)*sin(x);
%function
f = @(x) exp(x).*cos(x);
central_scheme = (C(1)*f(x-(2*dx))+C(2)*f(x-dx)+C(3)*f(x)+C(4)*f(x+dx)+C(5)*f(x+(2*dx)))./(dx.^2);
right_skewed = (R(1)*f(x)+R(2)*f(x+dx)+R(3)*f(x+(2*dx))+R(4)*f(x+(3*dx))+R(5)*f(x+(4*dx))+R(6)*f(x+(5*dx)))./(dx.^2);
left_skewed = (L(1)*f(x-(5*dx))+L(2)*f(x-(4*dx))+L(3)*f(x-(3*dx))+L(4)*f(x-(2*dx))+L(5)*f(x-dx)+L(6)*f(x))./(dx.^2);
error_central = abs(central_scheme-Analytical_Second_Derivative);
error_right_skewed = abs(right_skewed-Analytical_Second_Derivative);
error_left_skewed = abs(left_skewed-Analytical_Second_Derivative);
figure(1)
loglog(dx,error_central,'r')
hold on
loglog(dx,error_right_skewed,'b')
hold on
loglog(dx,error_left_skewed,'k')
legend('Central Difference', 'Skewed Right Sided', 'Skewed left Sided','location','northwest')
xlabel('Grid Size dx')
ylabel('Absolute Error')
The obtained result in the form of a log-log plot is:

A Skewed Scheme is useful in cases when we are given a boundary condition only on one side, for the central differencing method, we need to know the points on both sides, A skewed right-sided differencing method is used when we know the value immediately right to the given point, similarly, a left-handed differencing is used when we know a value immediately to the left of a given point. All three have their own demerits, we need to select the most suitable one for our given problem.