Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
I. Aim:
Derive fourth-order approximations of the second-order derivative using the central differential scheme, skewed right-sided difference, and skewed left-sided difference using the Taylor table method and compare the analytical derivative with the obtained values for the given function
1. Central difference
2. Skewed right-sided difference
3. Skewed left-sided difference
Interesting fact: Why is a higher order approximation desirable in the first place?
For the same mesh, we can get better accuracy, reduced number of mesh points, reduced computation time and storage. Therefore, any computation that requires the resolution of small length scales (ie, the important physics occurs on small length scales) or has very sharp spatial gradients is an ideal candidate for higher order differentiation.
SCHEME DERIVATIONS:
CENTRAL DIFFERENCING SCHEME:
NO OF NODES:
The number of nodes = p+q-1
Where, p is order of derivative.
q is order of approximations.
The no of nodes = 2+4-1 =>5
DERIVATION:
To derive a fourth order approximation for the second order derivative,we start with these approximation,

taylor series derivation for the above terms,

Simillarly expand all the terms in the equation (1) and are represented in the form of table using taylor table method.

the linear equation obtained from the above table are solved using matrix inversion method,
A.X = B

X = inv(A)*B
we get the coefficients as,

a=-0.0833, b=1.3333, c=-2.5000, d=1.3333 e=-0.0833
substituting these coefficient in equation(1) we get,

SKEWED RIGHT HAND DIFFERENCE SCHEME:
NO OF NODES:
The number of nodes = p+q
Where, p is order of derivative.
q is order of approximations.
The no of nodes = 2+4 =>6.
DERIVATION:
To derive a fourth order approximation for the second order derivative,we start with these approximation,

expand all the terms in the equation (2) using taylor series expansion and are represented in the form of table using taylor table method

the linear equation obtained from the above table are solved using matrix inversion method,
A.X = B

X = inv(A)*B
we get the coefficients as,

a=3.7500, b=-12.8333, c=17.8333, d=-13.0000 e=5.0833 g=-0.8333
substituting these coefficient in equation(3) we get

SKEWED LEFT HAND DIFFERENCE SCHEME:
NO OF NODES:
The number of nodes = p+q
Where, p is order of derivative.
q is order of approximations.
The no of nodes = 2+4 =>6
DERIVATION:
To derive a fourth order approximation for the second order derivative,we start with these approximation,

expand all the terms in the equation (3) using taylor series expansion and are represented in the form of table using taylor table method.

the linear equation obtained from the above table are solved using matrix inversion method,
A.X = B

X = inv(A)*B
we get the coefficients as,

a=-0.8333, b=5.0833, c=-13.0000, d=17.8333 e=-12.8333 g=3.7500

function codes central differencing;
function Error_central_differencing = fourth_order_central_differencing(x,dx)
% analytic function = exp(x)*cos(x)
% analytic derivative
%f''(x) = -2*exp(x)*sin(x)
analytical_derivative = -2*exp(x)*sin(x);
%numerical derivative
%central differencing
central_differencing = (((-0.0833)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))+((1.3333)*((exp(x-dx))*(cos(x-dx))))-((2.5000)*((exp(x))*(cos(x))))+((1.3333)*((exp(x+dx))*(cos(x+dx))))-((0.0833)*((exp(x+(2*dx)))*(cos(x+(2*dx))))))/(dx^2);
%error
Error_central_differencing = abs(central_differencing- analytical_derivative);
end
function code for right sided skew;
function Error_right_sided_skew = fourth_order_right_sided_skew(x,dx)
% analytic function = exp(x)*cos(x)
% analytic derivative
%f''(x) = -2*exp(x)*sin(x)
analytical_derivative = -2*exp(x)*sin(x);
%numerical derivative
%central differencing
right_sided_skew = (((3.7500)*((exp(x))*(cos(x))))-((12.8333)*((exp(x+dx))*(cos(x+dx))))+((17.8333)*((exp(x+(2*dx)))*(cos(x+(2*dx)))))-((13.0000)*((exp(x+(3*dx)))*(cos(x+(3*dx)))))+((5.0833)*((exp(x+(4*dx)))*(cos(x+(4*dx)))))-((0.8333)*((exp(x+(5*dx)))*(cos(x+(5*dx))))))/(dx^2);
%error
Error_right_sided_skew = abs(right_sided_skew- analytical_derivative);
end
function code for left sided skew;
function Error_left_sided_skew = fourth_order_left_sided_skew(x,dx)
% analytic function = exp(x)*cos(x)
% analytic derivative
%f''(x) = -2*exp(x)*sin(x)
analytical_derivative = -2*exp(x)*sin(x);
%numerical derivative
%central differencing
left_sided_skew = (((-0.8333)*((exp(x-(5*dx)))*(cos(x-(5*dx)))))+((5.0833)*((exp(x-(4*dx)))*(cos(x-(4*dx)))))-((13.0000)*((exp(x-(3*dx)))*(cos(x-(3*dx)))))+((17.8333)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))-((12.8333)*((exp(x-dx))*(cos(x-dx))))+((3.7500)*((exp(x))*(cos(x)))))/(dx^2);
%error
Error_left_sided_skew = abs(left_sided_skew- analytical_derivative);
end
Matlab main code;
clear all
close all
clc
%value of x
x= pi/3;
%range of dx
dx= linspace(pi/40,pi/4000,20);
%for loop
for i=1:length(dx)
central_differencing(i) = fourth_order_central_differencing(x,dx(i));
right_sided_skew(i) = fourth_order_right_sided_skew(x,dx(i));
left_sided_skew(i) = fourth_order_left_sided_skew(x,dx(i));
end
%plotting
figure(1)
loglog(dx,central_differencing,'r')
hold on
loglog(dx,right_sided_skew,'g')
hold on
loglog(dx,left_sided_skew,'b')
xlabel('range of dx')
ylabel('truncation error')
title('range of dx vs error')
legend('central differencing','skewed right sided difference','skewed left sided difference','location','northwest')
OUTPUT:

CONCLUSION:
As can be seen from the graph, the central difference scheme has very less errors compared to other schemes. Therefore, central differencing is superior to other schemes because it uses information from both sides of the reasoning to provide approximate and exact values.
Since the left-right skewed difference method uses data from only one side of the point of interest, it provides less approximate and accurate values about the point.
WHY A TRIED SCHEME IS USEFUL:
A system that does not contain sufficient information on either side of the point of interest. In such cases, we cannot use the central difference scheme, so the skew scheme is useful in such cases.
WHAT A SLIP SCHEME CAN DO THAT A CD SCHEME CANNOT:
CDS cannot be used on border nodes due to unavailability of right and left nodes at the same time. In such cases, the skewed difference scheme is used.