Challenge

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

Deriving 4th order approximation of a 2nd order derivative using Taylor table method

Aim:

To derive 4th order approximation of a second order derivative

i)Central derivative approximation method

ii)Skewed right hand approximation method

iii)Skewed left hand approximation method

by using Taylor’s Table and to plot the error difference between them.

Objective:

To derive equation for the above-mentioned method and to find the constants using Taylor’s table.

To compare the observed error difference by plotting them.

Deriving 4th order approximation of a second order derivative by Central derivative approximation method

To find No.of.Nodes for CDA

No.of.Nodes = Order of derivative(P) + Order of approximation(Q) – 1

= 2+4-1

= 5

∆x 2 d2u/dx2 = a f(i-2) +b f(i-1) +c f(i)+d f(i+1) +e f(i+2)

By applying Taylor series

a (f(i-2)) = a [ f(i)-2∆xf’(i)+(2∆x)2 f’’(i)/2! – (2∆x)3f’’’(i)/3!+(2∆x)4fiv(i)/4!]

b (f(i-1)) = b [ f(i)- ∆xf’(i)+(∆x)2 f’’(i)/2! – (∆x)3f’’’(i)/3!+(∆x)4fiv(i)/4!]

c (f(i)) = c [f(i)]

d (f(i-1)) = d [ f(i)+ ∆xf’(i)+(∆x)2 f’’(i)/2! +(∆x)3f’’’(i)/3!+(∆x)4fiv(i)/4!]

e (f(i+2)) = e [ f(i)+2∆xf’(i)+(2∆x)2 f’’(i)/2! + (2∆x)3f’’’(i)/3!+(2∆x)4fiv(i)/4!]

By applying Taylor’s Table

f(i)

f’(i)∆x

f’’(i)∆x2

f’’’(i)∆x3

fiv (i)∆x4

a(f(i-2))

a

-2a

4a/2

-8a/6

16a/24

b (f(i-1))

b

b

b/2

-b/6

b/24

c (f(i))

c

0

0

0

0

d (f(i+1))

d

d

d/2

d/6

d/24

e (f(i+2))

e

2e

4e/2

8e/6

16e/24

d2u/dx2

0

0

1

0

0

Converting the table in to equation

i.e

Equation -1 =a+b+c+d+e=0

Equation -2 =-2a-b+0+d+2e=0

Equation -3 =4a/2+b+0+d/2+4e/2=1

Equation -4 =-8a/6-b/6+0+d/6+8e/6=0

Equation -5 =16a/24+b/24+0d/24+16e/24=0

We have 5 unknowns & 5 Equations

ie by applying matrix

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

X=AB

i.e

a=-1/12, b=4/3, c=-5/2, d=4/3, e=-1/2

applying the constant in the main equation

d2u/dx2 = (((-1/12) *(exp(x-2*dx) *cos(x-2*dx))) +(4/3) *exp(x-dx) *cos(x-dx) +(-5/2) *exp(x)*cos(x)+(4/3) *exp(x+dx) *cos(x+dx) +(-1/12) *exp(x+2*dx) *cos(x+2*dx)) *1/dx^2;

Deriving 4th order approximation of a second order derivative by Skewed Righthand approximation method

To find No.of.Nodes for Skewed Righthand

No.of.Nodes = Order of derivative(P) + Order of approximation(Q)

= 2+4

= 6

∆x 2 d2u/dx2 = g f(i) +h f(i+1) +j f(i+2) +k f(i+3) +l f(i+4) +m f(i+5)

By applying Taylor series

g (f(i)) = g [ f(i)]

h (f(i+1)) = h [ f(i)+ ∆xf’(i)+(∆x)2 f’’(i)/2! +(∆x)3f’’’(i)/3!+(∆x)4fiv(i)/4!+ (∆x)5fv(i)/5!]

j (f(i+2)) = j [ f(i)+2∆xf’(i)+(2∆x)2 f’’(i)/2! + (2∆x)3f’’’(i)/3!+(2∆x)4fiv(i)/4!+ (2∆x)5fv(i)/5!]

k (f(i+3)) = k [ f(i)+3∆xf’(i)+(3∆x)2 f’’(i)/2! + (3∆x)3f’’’(i)/3!+(3∆x)4fiv(i)/4!+ (3∆x)5fv(i)/5!]

l (f(i+4)) = l [ f(i)+4∆xf’(i)+(4∆x)2 f’’(i)/2! + (4∆x)3f’’’(i)/3!+(4∆x)4fiv(i)/4!+ (4∆x)5fv(i)/5!]

m (f(i+5)) = m [ f(i)+5∆xf’(i)+(5∆x)2 f’’(i)/2! + (5∆x)3f’’’(i)/3!+(5∆x)4fiv(i)/4!+ (5∆x)5fv(i)/5!]

By applying Taylor’s Table

f(i)

f’(i)∆x

f’’(i)∆x2

f’’’(i)∆x3

fiv (i)∆x4

fv (i)∆x5

g (f(i))

g

0

0

0

0

0

h (f(i+1))

h

h

h/2

h/6

h/24

h/120

J (f(i+2))

j

2j

4j/2

8j/6

16j/24

32j/120

k (f(i+3))

k

3k

9k/2

27k/6

81k/24

243k/120

l (f(i+4))

l

4l

16l/2

64l/6

256l/24

1024l/120

m (f(i+5))

m

5m

25m/2

125m/6

625m/24

3125m/120

d2u/dx2

0

0

1

0

0

0

Converting the table in to equation

i.e

Equation -1 =g+h+j+k+l+m=0

Equation -2 =-h+2j+3k+4l+5m=0

Equation -3 =h/2+4j/2+9k/2+16l/2+25m/2=1

Equation -4 =h/6+8j/6+27k/6+64l/6+125m/6=0

Equation -5 =h/24+16j/24+81k/24+256l/24+1024l/24=0

Equation -6 =h/120+32j/120+243k/120+1024l/120+3125m/120=0

We have 6 unknowns & 6 Equations

ie by applying matrix

C= 1 1 1 1 1 1

0 1 2 3 4 5

0 1/2 2 9/2 8 25/2

0 1/6 4/3 9/2 32/3 125/6

0 1/24 2/3 27/8 32/3 625/24

0 1/120 4/15 81/40 128/15 625/24

D=

0

0

1

0

0

0

Y=CD

i.e g=15/4, h=-77/6, j=107/6, k=-13, l=61/12, m=-5/6

applying the constant in the main equation

d2u/dx2 = ((15/4)*exp(x)*cos(x)+(-77/6)*exp(x+dx)*cos(x+dx)+(107/6)*exp(x+2*dx)*cos(x+2*dx)+(-13)*exp(x+3*dx)*cos(x+3*dx)+(61/12)*exp(x+4*dx)*cos(x+4*dx)+(-5/6)*exp(x+5*dx)*cos(x+5*dx))/dx^2

Deriving 4th order approximation of a second order derivative by Skewed left-hand approximation method

To find No.of.Nodes for Skewed left-hand

No.of.Nodes = Order of derivative(P) + Order of approximation(Q)

= 2+4

= 6

∆x 2 d2u/dx2 = n f(i) +t f(i-1) +p f(i-2) +q f(i-3) +r f(i-4) +s f(i-5)

By applying Taylor series

n (f(i)) = n [ f(i)]

t (f(i-1)) = t [ f(i)- ∆x f’(i)+(∆x)2 f’’(i)/2! -(∆x)3f’’’(i)/3! +(∆x)4fiv(i)/4! - (∆x)5fv(i)/5!]

p (f(i-2)) = p [ f(i)-2∆x f’(i)+(2∆x)2 f’’(i)/2! - (2∆x)3f’’’(i)/3! +(2∆x)4fiv(i)/4! - (2∆x)5fv(i)/5!]

q (f(i-3)) = q [ f(i)-3∆x f’(i)+(3∆x)2 f’’(i)/2! - (3∆x)3f’’’(i)/3! +(3∆x)4fiv(i)/4! - (3∆x)5fv(i)/5!]

r (f(i-4)) = r [ f(i)-4∆x f’(i)+(4∆x)2 f’’(i)/2! - (4∆x)3f’’’(i)/3! +(4∆x)4fiv(i)/4! - (4∆x)5fv(i)/5!]

s (f(i-5)) = s [ f(i)-5∆x f’(i)+(5∆x)2 f’’(i)/2! - (5∆x)3f’’’(i)/3! +(5∆x)4fiv(i)/4! - (5∆x)5fv(i)/5!]

By applying Taylor’s Table

f(i)

f’(i)∆x

f’’(i)∆x2

f’’’(i)∆x3

fiv (i)∆x4

fv (i)∆x5

n (f(i))

n

0

0

0

0

0

t (f(i+1))

t

-t

t/2

-t/6

t/24

-t/120

p (f(i+2))

p

-2p

4p/2

-8p/6

16p/24

-32p/120

q (f(i+3))

q

-3q

9q/2

-27q/6

81q/24

-243q/120

r (f(i+4))

r

-4r

16r/2

-64r/6

256r/24

-1024r/120

s (f(i+5))

s

-5s

25s/2

-125s/6

625s/24

-3125s/120

d2u/dx2

0

0

1

0

0

0

Converting the table in to equation

i.e

Equation -1 =n+t+p+q+r+s=0

Equation -2 =-t-2p-3q-4r-5s=0

Equation -3 =t/2+4p/2+9q/2+16r/2+25s/2=1

Equation -4 =-t/6-8p/6-27q/6-64r/6-125s/6=0

Equation -5 =t/24+16p/24+81q/24+256r/24+1024s/24=0

Equation -6 =-t/120-32p/120-243q/120-1024r/120-3125s/120=0

We have 6 unknowns & 6 Equations

ie by applying matrix

E= 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

F= 0

0

1

0

0

0

Z=EF

i.e n=15/4, t=-77/6, p=107/6, q=-13, r=61/12, s=-5/6

d2u/dx2= ((15/4) *exp(x)*cos(x)+(-77/6) *exp(x-dx) *cos(x-dx)+(107/6)*exp(x-2*dx)*cos(x-2*dx)+(-13)*exp(x-3*dx)*cos(x-3*dx)+(61/12)*exp(x-4*dx)*cos(x-4*dx)+(-5/6)*exp(x-5*dx)*cos(x-5*dx))/dx^2

Main Program

clear all
close all
clc
x=pi/3;
dx=linspace(pi/40,pi/4000,20);

for i=1:length(dx)
    central_order_error(i)=central_approximation(x,dx(i));
    skewed_righthand_error(i)=skewed_righthand_approximation(x,dx(i));
    skewed_lefthand_error(i)=skewed_lefthand_approximation(x,dx(i));
    
end
figure(1)
loglog(dx,central_order_error)
hold on
loglog(dx,skewed_righthand_error,'r')
loglog(dx,skewed_lefthand_error,'g')
xlabel('dx')
ylabel('error')
legend('central order approximation error','skewed right hand approximation error','skewed left hand approximation error','location','best')
title('Error comparison')

Program for finding constant

clear all
close all
clc
%Skewed right hand method
A=[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]
B=[0;0;1;0;0;0]
X=AB
%Skewed left hand method
C=[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]
D=[0;0;1;0;0;0]
Y=CD
%Central differncing approximation
E=[1 1 1 1 1;-2 -1 0 1 2;4/2 1/2 0 1/2 4/2;-8/6 -1/6 0 1/6 8/6;16/24 1/24 0 1/24 16/24];
F=[0;0;1;0;0];
Z=EF

Function program for central approximation

 function out=central_approximation(x,dx)
analytical_derivative =-2*exp(x)*sin(x);
%fourth_order_approximation
%central_differencing =a f(i-2)+b f(i-1)+c f(i)+d f(i+1)+e f(i+2)
%f''(x)=(-1/12 f(x-(2*dx))-4/3*(f(x-dx))-5/2+4/3*(f(x+dx))-1/12f(x+(2*dx)))/dx^2)
central_differencing =(((-1/12)*(exp(x-2*dx)*cos(x-2*dx)))+(4/3)*exp(x-dx)*cos(x-dx)+(-5/2)*exp(x)*cos(x)+(4/3)*exp(x+dx)*cos(x+dx)+(-1/12)*exp(x+2*dx)*cos(x+2*dx))/dx^2;
out=abs(central_differencing-analytical_derivative);

Function program for skewed right hand approximation

function out=skewed_righthand_approximation(x,dx)
analytical_derivative =-2*exp(x)*sin(x);
%skewed_righthand_approximation
%skewed_right hand =a f(x)+bf(x+dx)+cf(x+2dx)+d f(x+3dx)+e f(x+4dx)+g f(x+5dx)
%f''(x)=(15/4)*exp(x)*cos(x)+(-77/6)*exp(x+dx)*cos(x+dx)+(107/6)*exp(x+2dx)*cos(x+2dx)+(-13)*exp(x+3dx)*cos(x+3dx)+(61/12)*exp(x+4dx)*cos(x+4dx)+(-5/6)*exp(x+5dx)*cos(x+5dx)
skewed_righthand =((15/4)*exp(x)*cos(x)+(-77/6)*exp(x+dx)*cos(x+dx)+(107/6)*exp(x+2*dx)*cos(x+2*dx)+(-13)*exp(x+3*dx)*cos(x+3*dx)+(61/12)*exp(x+4*dx)*cos(x+4*dx)+(-5/6)*exp(x+5*dx)*cos(x+5*dx))/dx^2;
out=abs(skewed_righthand-analytical_derivative)

Function program for skewed left hand approximation

function out=skewed_lefthand_approximation(x,dx)
analytical_derivative =-2*exp(x)*sin(x);
%skewed_lefthand_approximation
%skewed_leftt hand =a f(x)+bf(x-dx)+cf(x-2dx)+d f(x-3dx)+e f(x-4dx)+g f(x-5dx)
%f''(x)=(15/4)*exp(x)*cos(x)+(-77/6)*exp(x-dx)*cos(x-dx)+(107/6)*exp(x-2dx)*cos(x-2dx)+(-13)*exp(x-3dx)*cos(x-3dx)+(61/12)*exp(x-4dx)*cos(x-4dx)+(-5/6)*exp(x-5dx)*cos(x-5dx)
skewed_leftthand =((15/4)*exp(x)*cos(x)+(-77/6)*exp(x-dx)*cos(x-dx)+(107/6)*exp(x-2*dx)*cos(x-2*dx)+(-13)*exp(x-3*dx)*cos(x-3*dx)+(61/12)*exp(x-4*dx)*cos(x-4*dx)+(-5/6)*exp(x-5*dx)*cos(x-5*dx))/dx^2;
out=abs(skewed_leftthand-analytical_derivative);

Conclusion

Thus, by deriving the 4th order approximation for second order derivative by Central boundary condition approach, skewed right hand &left-hand method we conclude that the error of approximation is less in Central approximation < Skewed left hand < Skewed right-hand methods. Hence the Skewed method can be used at boundary condition where symmetric stencil is not possible.

Note: Plot for the above methods & executed program are attached below

Q:Why a skewed scheme is useful?

Ans: Skewed scheme is more efficient when we solve for the boundary condition of the system where symmetric stencil won’t be available.

What can a skewed scheme do that a CD scheme cannot?

By using skewed scheme, we can solve a non-symmetric stencil boundary condition.

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.