Challenge

Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method

AIM

To derive the fourth order approxiamtion of second order derivative using central difference, skewed right side difference and skewed left side difference.

Central difference method

The order of accuracy P = Number of nodes in the stencil N - order of derivative Q + 1

P=N-Q+1

N=P+Q-1=4+2-1=5

We have 5 point in the stencil

Assume dx is the distance between nodes in the stencil

We assume the expression as

`(del^2f)/(delx^2) = af(x-2dx)+bf(x-dx)+cf(x)+df(x+dx)+ef(x+2dx)`

Taylor series expansion of each term is given by

`af(x-2dx) = af(x) - a(f'(x)*(2dx))/(1!)+a(f''(x)(2dx)^2)/(2!)+a(f'''(x)(2dx)^3)/(3!)+a(f''''(x)(2dx)^4)/(4!)-...`

`bf(x-dx)=bf(x)-b(f'(x)(x))/(1!)+b*(f''(x)(dx)^2)/(2!)-b*(f'''(x)(dx)^3)/(3!)+b*(f''''(x)(dx^4))/(4!)-...`

cf(x)=cf(x)

`df(x+dx)=df(x)+d*(f'(x)(dx))/(1!)+d*(f''(x)(dx)^2)/(2!)+d(f'''(x)(dx)^3)/(3!)+d*(f''''(x)(dx)^4)/(4!)+...`

`ef(x+2dx)=ef(x)+e*(f'(x)(dx))/(1!)+e*(f''(x)(dx)^2)/(2!)+e*(f'''(x)(dx)^3)/(3!)+e(f''''(x)(dx)^4)/(4!)+...`

Writing the taylor table

  f(x) f'(x)dx `f''(x)(dx)^2` `f'''(x)(dx)^3` `f''''(x)(dx)^4`
af(x-2dx) a -2a (4/2)a (-8/6)a (16/24)a
bf(x-dx) b -b b/2 (-1/6)b (1/24)b
cf(x) c 0 0 0 0
df(x+dx) d d d/2 (1/6)d (1/24)d
ef(x+2dx) e 2e (4/2)e (8/6)e (16/24)e
           
Sum 0 0 1 0 0

Solving the matrix using inversion gives 

a=-0.0833

b=1.3333

c=-2.5000

d=1.3333

e=-0.0833

With truncation error of order of 4

`f''(x)(dx^2)=af(x-2dx)+bf(x-dx)+cf(x)+df(x+dx)+ef(x+2dx)`

`f''(x) = (-0.0833f(x-2dx)+1.3333f(x-dx)-2.5f(x)+1.3333f(x+dx)-0.0833f(x+2dx))/(dx^2)`

Skewed Right sided difference

The order of accuracy P = Number of nodes in the stencil N - order of derivative Q

4=N-2

N=4+2=6

we have 6 nodes

consider 6 equidistant points with dx as the distance between them.

The points from left to right are named respectively f(x), f(x+dx), f(x+2dx), f(x+3dx), f(x+4dx), f(x+5dx).

We assume the expression as

`(del^2f)/(delx^2) = gf(x)+hf(x+dx)+if(x+2dx)+jf(x+3dx)+kf(x+4dx)+lf(x+5dx)`

Where g,h,i,j,k,l are constants of approximation

Taylor series expansion of each term is given by

`gf(x)=gf(x)`

`hf(x+dx)=hf(x)+h*(f'(x)(dx))/(1!)+h*(f''(x)(dx)^2)/(2!)+h*(f'''(x)(dx)^3)/(3!)+h*(f''''(x)(dx)^4)/(4!)+h*(f'''''(x)(dx)^5)/(5!)+...`

`if(x+2dx)=if(x)+i*(f'(x)(2dx))/(1!)+i*(f''(x)(2x)^2)/(2!)+i*(f'''(x)(2dx)^3)/(3!)+i*(f''''(x)(2dx)^4)/(4!)+i*(f'''''(x)(2dx)^5)/(5!)+...`

`jf(x+3dx)=jf(x)+j*(f'(x)(3dx))/(1!)+j*(f''(x)(3dx)^2)/(2!)+j*(f'''(x)(3dx)^3)/(3!)+j*(f''''(x)(3dx)^4)/(4!)+j*(f'''''(x)(3dx)^5)/(5!)+...`

`kf(x+4dx)=kf(x)+k*(f'(x)(4dx))/(1!)+k*(f''(x)(4dx)^2)/(2!)+k(f'''(x)(4dx)^3)/(3!)+k*(f''''(x)(4dx)^4)/(4!)+k*(f'''''(x)(4dx)^5)/(5!)+...`

`lf(x+5dx)=lf(x)+l*(f'(x)(5dx))/(1!)+l*(f''(x)(5dx)^2)/(2!)+l*(f'''(x)(5dx)^3)/(3!)+l*(f''''(x)(5dx)^4)/(4!)+l*(f'''''(x)(5dx)^5)/(5!)+...`

 Writing the taylor table

  f(x) f'(x)dx `f''(x(dx)^2` `f'''(x)(dx)^3` `f''''(x)(dx)^4` `f'''''(x)(dx)^5`
gf(x) g 0 0 0 0 0
hf(x+dx) h h (1/2)h (1/6)h (1/24)h (1/120)
if(x+2dx) i 2i (4/2)i (8/6)i (2/3)i (4/15)i
jf(x+3dx) j 3j (9/2)j (9/2)j (27/8)j (81/40)j
kf(x+4dx) k 4k 8k (32/2)k (32/3)k (128/15)k
lf(x+5dx) l 5l (25/2)l (125/6)l (625/24)l (625/24)l
             
sum 0 0 1 0 0 0

 Solving for g,h,i,j,k,l using matrix inversion gives

g=3.7500

h=-12.8333

i=17.8333

j=-13.0000

k=5.0833

l=-0.8333

 With truncation error of order of 4

`f''(x)(dx^2)=gf(x)+hf(x+dx)+if(x+2dx)+jf(x+3dx)+kf(x+4dx)+lf(x+5dx)`

`f''(x) = (3.75*f(x)-12.833f(x+dx)+17.8333*f(x+2dx)-13.0000f(x+3dx)+5.0833*f(x+4dx)-0.8333*f(x+5dx))/(dx^2)`

Skewed Left sided difference

The order of accuracy P = Number of nodes in the stencil N - order of derivative Q

4=N-2

N=4+2=6

we have 6 nodes

consider 6 equidistant points with dx as the distance between them.

The points from left to right are named respectively f(x-5dx), f(x-4dx), f(x-3dx), f(x-2dx), f(x-dx), f(x).

We assume the expression as

`(del^2f)/(delx^2) = rf(x-5dx)+sf(x-4dx)+tf(x-3dx)+uf(x-2dx)+vf(x-dx)+wf(x)`

Where r,s,t,u,v,w are constants of approximation

Taylor series expansion of each term is given by

`rf(x-5dx)=rf(x)-r*(f'(x)(5dx))/(1!)+r*(f''(x)(5dx)^2)/(2!)-r*(f'''(x)(5dx)^3)/(3!)+r*(f''''(x)(5dx)^4)/(4!)-r*(f'''''(x)(5dx)^5)/(5!)+...`

`s.f(x-4dx)=s.f(x)-s*(f'(x)(4dx))/(1!)+s*(f''(x)(4dx)^2)/(2!)-s*(f'''(x)(4dx)^3)/(3!)+s*(f''''(x)(4dx)^4)/(4!)-s*(f'''''(x)(4dx)^5)/(5!)+...`

`tf(x-3dx)=tf(x)-t*(f'(x)(3dx))/(1!)+t*(f''(x)(3dx)^2)/(2!)-t*(f'''(x)(3dx)^3)/(3!)+t*(f''''(x)(3dx)^4)/(4!)-t*(f'''''(x)(3dx)^5)/(5!)+...`

`uf(x-2dx)=uf(x)-u*(f'(x)(2dx))/(1!)+u*(f''(x)(2x)^2)/(2!)-u*(f'''(x)(2dx)^3)/(3!)+u*(f''''(x)(2dx)^4)/(4!)-u*(f'''''(x)(2dx)^5)/(5!)+...`

`vf(x-dx)=vf(x)-v*(f'(x)(dx))/(1!)+v*(f''(x)(dx)^2)/(2!)-v*(f'''(x)(dx)^3)/(3!)+v*(f''''(x)(dx)^4)/(4!)-v*(f'''''(x)(dx)^5)/(5!)+...`

`wf(x)=wf(x)`

 Writing the taylor table

  f(x) f'(x)dx `f''(x(dx)^2` `f'''(x)(dx)^3` `f''''(x)(dx)^4` `f'''''(x)(dx)^5`
rf(x-5dx) r -5r (25/2) (-125/6)r (625/24)r (-625/24)r
sf(x-4dx) s -4s 8s (-32/3)s (32/3)s (-128/15)s
tf(x-3dx) t -3t (9/2)t (-9/2)t (27/8)t (-81/40)t
uf(x-2dx) u -2u (4/2)u (-8/6)u (2/3)u (-4/15)u
vf(x-dx) v -1v (1/2)v (-1/6)v (1/24)v (-1/120)v
wf(x) w 0 0 0 0 0
             
sum 0 0 1 0 0 0

 Solving for r,s,t,u,v,w using matrix inversion gives

r=-0.8333

s=5.0833

t=-13.0000

u=17.8333

v=-12.8333

w=3.7500

 With truncation error of order of 4

`f''(x)(dx^2)=rf(x-5dx)+sf(x-4dx)+tf(x-3dx)+uf(x-2dx)+vf(x-dx)+wf(x)`

`f''(x) = (-0.8333*f(x-5dx)+5.0833f(x-4dx)-13.0000*f(x-3dx)+17.8333*f(x-2dx)-12.8333*f(x-dx)+3.7500*f(x))/(dx^2)`

The given function `cos(x).e^(x)` needs to be evaluated at second order derivative using the exact differential and the 3 types of approxiamtion.

 MATLAB Code

clear all
close all
clc
 
% assuming values for x and dx as following
x = pi/3;
dx=linspace(pi/4000,pi/40,20);
 
% f(x) = cos(X)*exp(x)
 
%exact second derivative is given by
exact = -2*(sin(x))*exp(x);
 
% second derivative calculation using central difference fourth order approximation
central_fourth_order = (((-0.0833).*(exp(x-(2.*dx))).*(cos(x-(2.*dx))))+((1.3333).*(exp(x-dx)).*(cos(x-dx)))+((-2.5).*(exp(x)).*(cos(x)))+((1.3333).*(exp(x+dx)).*(cos(x+dx)))+((-0.0833).*(exp(x+(2.*dx))).*(cos(x+(2.*dx)))))./(dx.^2);
 
% second order derivative calculation using skewed right sided difference
% fourth order approximation
right_fourth_order = (((3.75).*(cos(x)).*(exp(x)))+((-12.8333).*(cos(x+dx)).*(exp(x+dx)))+((17.8333).*(cos(x+(2.*dx))).*(exp(x+(2.*dx))))+((-13.00).*(cos(x+(3.*dx))).*(exp(x+(3.*dx))))+((5.0833).*(cos(x+(4.*dx))).*(exp(x+(4.*dx))))+((-0.8333).*(cos(x+(5.*dx))).*(exp(x+(5.*dx)))))./(dx.^2);
 
%second order derivative calculation using skewed left sided difference
%fourth order approximation
left_fourth_order = (((-0.8333).*(cos(x-(5.*dx))).*(exp(x-(5.*dx))))+((5.0833).*(cos(x-(4.*dx))).*(exp(x-(4.*dx))))+((-13.00).*(cos(x-(3.*dx))).*(exp(x-(3.*dx))))+((17.8333).*(cos(x-(2.*dx))).*(exp(x-(2.*dx))))+((-12.8333).*(cos(x-dx)).*(exp(x-dx)))+((3.75).*(cos(x)).*(exp(x))))./(dx.^2);
 
%error calculation
error_central = abs(exact-central_fourth_order);
error_right= abs(exact-right_fourth_order);
error_left = abs(exact-left_fourth_order);
 
%plotting error vs dx
plot(dx,error_central,'color','r')
hold on
plot(dx,error_right,'color','g')
hold on
plot(dx,error_left,'color','b')
title('dx vs error for various types of approximation')
xlabel('dx')
ylabel('error')
legend('central','right sided','left sided')
 
Result
 
 
As the distance between two nodes decreases the error in approximation also decreases.
 

WHY A SKEWED SCHEME IS USEFUL:

The system which doesn’t contain sufficient information on both side of the point of interest. In such cases we cannot use central differencing scheme so skewed scheme is useful in such cases.

WHAT CAN A SKEWED SCHEME DO THAT A CD SCHEME CANNOT DO:

CDS cannot not be employed at the boundary nodes due to unavailability of right and left nodes at the same time. In such cases the skewed differencing scheme is use

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.