Taylor Table Method using skewed and symmetric stencil
OBJECTIVE
To derive the fourth order approximation for the seconf order derivative by symmetric and skewed stencils
1. Central differencing
2.Skewed left side differencing
3.Skewed right side differencing
Central right side differencing
Cental differencing approximation is calculated for the central node by calculating the values for the successive nodes on both sides of the node.Hence it follows a symmetrical stencil
consider five nodes points that is (i-2),(i-1),(i),(i+1),(i+2).The second order derivative is calculated using the formula below
`(d^2f)/(dx^2)=(af_(i-2)+bf_(i-1)+cf_(i)+df_(i+2)+ef_(i+2))/dx^2+0(dx^4)`
stencil f(i) `triangle`f\'(i) `triangle^2`f\'\'(i) `triangle^3`f\'\'\'(i) `triangle^4f\'\'\'\'(i)`
af(i-2) a -2a 2a -4a/3 2a/3
bf(i-1) b -b b/2 -b/6 b/24
cf(i) c 0 0 0 0
df(i+1) d d d/2 d/6 d/24
ef(i+2) e 2e 2e 4e/3 2e/3
a+b+c+d+e=0
-2a-b+d+2e=0
2a+b/2+d/2+2e=1
-4a/3-b/6+d/6+4e/3=0
2a/3+b/24+d/24+2e/3=0
AX=B
Schewed left hand scheme
points to be considered are (i-4),(i-3),(i-2),(i-1),(i).The approximation are calculated on the left side of the node
`(d^2f)/(dx^2)=(af_(i-4)+bf_(i-3)+cf_(i-2)+df_(i-1)+ef_(i))/dx^2+0(dx^4)`
stencil f(i) `triangle`f\'(i) `triangle^2`f\'\'(i) `triangle^3`f\'\'\'(i) `triangle^4f\'\'\'\'(i)`
af(i-2) a -4a 8a -32a/3 32a/3
bf(i-1) b -3b 9b/2 -9b/2 27b/8
cf(i) c -2c 2c 4c/3 2c/3
df(i+1) d -d d/2 -d/6 d/24
ef(i+2) e 0 0 0 0
1 0 1 0 0
a+b+c+d+e=0
-4a-3b-3c-d=0
8a+9b/2+2c+d/2=1
-32a/3-9b/2-4c/3-d/6=1
32a/3+27/8+2c/3+d/24=0
AX=B
Matrix form
Schewed right hand scheme
The approximationa are taken on the right side of the node.The points are as follows (i-4),(i-3),(i-2),(i-1),(i)
`(d^2f)/(dx^2)=(af_(i)+bf_(i+1)+cf_(i+2)+df_(i+3)+ef_(i+4))/dx^2+0(dx^4)`
stencil f(i) `triangle`f\'(i) `triangle^2`f\'\'(i) `triangle^3`f\'\'\'(i) `triangle^4f\'\'\'\'(i)`
af(i-2) a 0 0 0 0
bf(i-1) b b b/2 b/6 b/24
cf(i) c -2c 2c 4c/3 2c/3
df(i+1) d 3d 9d/2 9d/2 27d/8
ef(i+2) e 4e 8e 32e/3 32e/3
1 0 1 0 0
a+b+c+d+e=0
b+2c+3d+4e=0
b/2+2c+9d/2+8e=1
b/6+4c/3+9d/2+32e/3=0
b/24+2c/3+27d/8+32e/3=0
Matrix form
Main code
clear all
close all
clc
%taylor table method
%input
x=pi/3;
dx=linspace(pi/4,pi/4000,20)
%Error calculation for the scheme for a range dc using the for loop
for i=1:length(dx)
error_central(i)=central_differencings(x,dx(i))
error_skw_left(i)=skewedleft_hand__differencing(x,dx(i))
error_skw_right(i)=skewedright_hand__differencing(x,dx(i))
end
%plotting the error against the grid space
loglog(dx,error_central,\'r\')
hold on
loglog(dx,error_skw_left,\'b\')
hold on
loglog(dx,error_skw_right,\'g\')
grid on
xlabel(\'dx\')
ylabel(\'error\')
legend(\'central diffferencing\',\'skewed left error\',\'skewed right error\')
function codes
function out=central_differencings(x,dx)
%function f(x)=exp(x)*cos(x)
%2nd order analytical derivative f\'\'(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x)
A=[1,1,1,1,1;-2,-1,0,1,2;2,1/2,0,1/2,2;-8/6,-1/6,0,1/6,8/6;16/24,1/24,0,1/24,16/24]
B=[0;0;1;0;0]
y=inv(A)*B
%central differencing
central_differencess=((y(1)*exp(x-2*dx)*cos(x-2*dx))+(y(2)*exp(x-dx)*cos(x-dx))......
+(y(3)*exp(x)*cos(x))+(y(4)*exp(x+dx)*cos(x+dx))+(y(5)*exp(x+2*dx)*cos(x+2*dx)))/(dx^2)
out =abs(central_differencess-analytical_derivative)
end
function out=skewedleft_hand__differencing(x,dx)
%function f(x)=exp(x)*cos(x)
%2nd order analytical derivative f\'\'(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x)
E=[1,1,1,1,1;-4,-3,-2,-1,0;8,9/2,2,1/2,0;-32/3,-9/2,-4/3,-1/6,0;32/3,27/8,2/3,1/24,0]
F=[0;0;1;0;0]
G=inv(E)*F
%central differencing
skewedleft_hand_difference=((G(1)*exp(x-4*dx)*cos(x-4*dx))+(G(2)*exp(x-3*dx)*cos(x-3*dx))......
+(G(3)*exp(x-2*dx)*cos(x-2*dx))+(G(4)*exp(x-dx)*cos(x-dx))+(G(5)*exp(x)*cos(x)))/(dx^2)
out =abs(skewedleft_hand_difference-analytical_derivative)
end
function out=skewedright_hand__differencing(x,dx)
%function f(x)=exp(x)*cos(x)
%2nd order analytical derivative f\'\'(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x)
C=[1,1,1,1,1;0,1,2,3,4;0,1/2,2,9/2,8;0,1/6,4/3,9/2,32/3;0,1/24,2/3,27/8,32/3]
D=[0;0;1;0;0]
K=inv(C)*D
%central differencing
skewedright_hand_difference=((K(1)*exp(x)*cos(x))+(K(2)*exp(x+dx)*cos(x+dx))......
+(K(3)*exp(x+2*dx)*cos(x+2*dx))+(K(4)*exp(x+3*dx)*cos(x+3*dx))+(K(5)*exp(x+4*dx)*cos(x+4*dx)))/(dx^2)
out =abs(skewedright_hand_difference-analytical_derivative)
end
Results
Conclusion
From teh above plots that it can be seen that the results obtained by central differencing schemes do vary largely with incremetn in the grid size where as the results for the skewed right side and skewed left differencing shows changes with the increament int he grid size.
It can be infer from the plots the central differencing technique are constant with the grid size and are more reliable,but at certain times we need to evaluate the results from either of the boundaries of the system .In such cases we conly take information from the nearest points which are either left or right side of the original point.So at such we need to use the skewed schemes.