Project

4th order approximations of the second order derivative using Central difference, Skewed right sided difference, Skewed left sided difference

Aim:To derive 4th order approximations of the second order derivative using

1. Central difference

2. Skewed right sided difference

3. Skewed left sided difference

Method used: Taylor table of finite difference method.

Theory:

The first step in obtaining a numerical solution is to discretize the geometric domain - i.e. a numerical grid must be defined.
In finite difference discretization methods the grid is usually locally structured that is each grid node may be considered the origin of a local co-ordinate system whose Axis coincide with grid lines.

Each node is uniquely identified by a set of Indices (i,j) which are the Indices of the grid lines that intersect at it (i,j) in 2D. The neighbour nodes are defined by increasing or reducing one of the Indices by unity (i+1) or (i-1)
The generic scalar conservation equation in differential form serves as the starting point for finite differential methods. As it is linear it will be approximated by a system of linear algebraic equations, in which the variable values at the grid nodes are the unknowns.
Each node thus has one unknown variable value associated with it and must provide one algebraic equation.when the boundary conditions involve derivatives, the boundary condition must be discritized to contribute an equation to the set that must be solved.

Taylor table is the collection of Taylor series representation. By using Taylor Table we can come up with Numerical schemes to meet the Target accuracy.


If the information used in forming the finite difference equation comes from the left of grid point then it is called backward differencing. In such differencing no information from the right side of the grid is used. (i.e. i,i-1). In the above fig. Dashed line represent Backward differencing.
If the information used in forming the finite difference equation come from the right side of the grid point, Then it is called forward differencing. In such differencing no information from the left side of the grid is used. (i.e. i,i+1). In the above fig. Dotted line represent Forward differencing.
If the information is used in forming the finite difference equation come from both left and right side of the grid, that it is called Central differencing. (i.e. i-1,i,i+1). In the above fig. Continoues line represent Central differencing.

SKEWED LEFT - Backward differencing scheme(BDS) :

No. of points needed for skewed differencing is = order of error + order of derivative

= 4 + 2

Therefore, 6 point stencil to be used.

Second order derivative of fourth order approximation for SLD is:

Taylor table for skewed left side difference of fourth order approximation

Matlab code to find above coefficients by using simple matrix inversion method:

clear all
close all
clc

%Finding coefficient for above table;
A=[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]
B=[0;0;1;0;0;0]

C=inv(A)*B

Thus,

a=3.75;
b=-12.8333;
c=17.8333;
d=-13;
e=5.0833;
f=-0.8333;

Central Differincing scheme (CDS:

No. of points needed for central differencing is = order of error + order of derivative - 1

= 4 + 2 - 1

Therefore, 5 point stencil to be used.

Second order derivative of fourth order approximation for CDS is:

Taylor table for Central difference of fourth order approximation:

Matlab code to find above coefficients by using simple matrix inversion method:

Thus,

Coefficient values for Central differencing
a1=-0.0833;
b1=1.3333;
c1=-2.5;
d1=1.3333;
e1=-0.0833;

RIGHT SKEWED - Forward differencing scheme (FDS) :

No. of points needed for skewed differencing is = order of error + order of derivative

= 4 + 2

Therefore, 6 point stencil to be used.

Second order derivative of fourth order approximation for SRD is:

Taylor table for skewed right side difference of fourth order approximation

Matlab code to find above coefficients by using simple matrix inversion method:

clear all
close all
clc

%Finding coefficient for above table;
A=[1 1 1 1 1 1;0 1 2 3 4 5;0 0.5 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];
B=[0;0;1;0;0;0];

C=inv(A)*B

output:

C = 3.7500 , -12.8333 , 17.8333 , -13.0000 , 5.0833 , -0.8333

Thus,

a=3.75;
b=-12.8333;
c=17.8333;
d=-13;
e=5.0833;
f=-0.8333;

Matlab code for creating functions of each differencing:

function [BDS_error,CDS_error,FDS_error]=taylor_table(x,dx)

%Given function = exp(x)*cos(x)
%analytical_answer= -2*sin(x)*exp(x)
%BDS - Backward differencing scheme
%CDS - Central differencing scheme
%FDS - Forward differencing schemed

%coefficient values for Central differencing
a1=-0.0833;
b1=1.3333;
c1=-2.5;
d1=1.3333;
e1=-0.0833;

%coefficient values for Forward and backward differencing
a=3.75;
b=-12.8333;
c=17.8333;
d=-13;
e=5.0833;
f=-0.8333;

BDS= (f*exp(x-5*dx)*cos(x-5*dx)+e*exp(x-4*dx)*cos(x-4*dx)+d*exp(x-3*dx)*cos(x-3*dx)+c*exp(x-2*dx)*cos(x-2*dx)+b*exp(x-dx)*cos(x-dx)+a*exp(x)*cos(x))/dx^2

CDS= (a1*exp(x-2*dx)*cos(x-2*dx)+b1*exp(x-dx)*cos(x-dx)+c1*exp(x)*cos(x)+d1*exp(x+dx)*cos(x+dx)+e1*exp(x+2*dx)*cos(x+2*dx))/dx^2

FDS= (f*exp(x+5*dx)*cos(x+5*dx)+e*exp(x+4*dx)*cos(x+4*dx)+d*exp(x+3*dx)*cos(x+3*dx)+c*exp(x+2*dx)*cos(x+2*dx)+b*exp(x+dx)*cos(x+dx)+a*exp(x)*cos(x))/dx^2

analytical_answer= -2*sin(x)*exp(x)

BDS_error = abs(BDS-analytical_answer)
CDS_error = abs(CDS-analytical_answer)
FDS_error = abs(FDS-analytical_answer)
end

Matlab code with explaination of 4th order approximations of the second order derivative using all 3 differincing methods:

close all
clear all
clc

%Given function = exp(x)*cos(x)
%analytical_answer= -2*sin(x)*exp(x)

%let us consider the values of x and dx
x=pi/3;
dx=linspace(pi/4,pi/4000,20);

for i=1:length(dx)
 [BDS_error(i),CDS_error(i),FDS_error(i)] = taylor_table(x,dx(i));
end


loglog(dx,BDS_error,'r')
hold on
loglog(dx,CDS_error,'b')
hold on
loglog(dx,FDS_error,'m')
grid on
xlabel('Range of dx')
ylabel('error magnitude')
legend('BDS','CDS','FDS','location','northwest')

Output:

Conclusion:

We can observe that for 2nd derivative 4th order Central differencing method gives the result with minimal error than forward or backward differencing.

But we cannot use central differencing everytime in case of boundaries as CDS uses information from both left and right neighbouring points, where as at boundaries there will be only either left neighbouring points or right neighbouring points.

In such cases, we must use Forward differencing or Backward differencing accordingly.

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.

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.