Deriving Forth Order Approximation Scheme of Second Order Derivative Using Taylor s Table
Objective:-
The objective is to derive the fourth order approximation of the skewed right-hand side scheme, skewed left-hand side scheme and the central difference scheme using Taylors table.
Central Difference Scheme
Stencil used for the forth order approximation for central difference scheme
The forth order central difference scheme approximation for the second derivative of f is given by
`(∂^2 f)/(∂^2 x)=af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2)`
The coefficent of Taylor series is enlisted in Taylor\'s table.
In the above Taylor\'s table, higher order derivatives are ignored as there only 5 unknown and we need 5 equation. The equation formed from the coefficent of `f^{\'\'}` can be assumed to be 1 as we need the approximation of second order derivative and rest of equation can be assumed to be zero.
`a+b+c+d+e=0→(i)`
`-2a∆x-b∆x+d∆x+2e∆x=0→(ii)`
`2a∆x^2+{b∆x^2}/2+{d∆x^2}/2+2e∆x^2=1→(iii)`
`-{8a∆x^3}/6 -{b∆x^3}/6+{d∆x^3}/6+{8e∆x^3}/6=0→(iv)`
`{16a∆x^4}/24+{b∆x^4)/24+{d∆x^4}/24+{16e∆x^4}/24=0→(v)`
Now, writting equation in matrix form, we get
AX=B
`[[1,1,1,1,1],[-2,-1,0,1,2],[4,1,0,1,4],[-8,-1,0,1,8],[16,1,0,1,16]][[a],[b],[c],[d],[e]]=[[0],[0],[2],[0],[0]]`
solving the matrix equation, we get
`[[a],[b],[c],[d],[e]]=[[-1/12],[4/3],[-15/6],[4/3],[-1/12]]`
Substituting these value, the forth order approximation for second derivative can be obtained,
`(∂^2 f)/(∂^2 x)={-f(i-2)+16f(i-1)-30f(i)+16f(i+1)-f(i+2)}/{12Deltax^2}`
Skewed Right-Hand Side Scheme
Stencil used for the forth order approximation for skewed right-hand side scheme.
The forth order skewed right-hand side scheme approximation for the second derivative of f is given by
`(∂^2 f)/(∂^2 x)=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+hf(i+5)`
The coefficent of Taylor series is enlisted in Taylor\'s table.
In the above Taylor\'s table, higher order derivatives are ignored as there only 6 unknown and we need 6 equation. The equation formed from the coefficent of `f^{\'\'}` can be assumed to be 1 as we need the approximation of second order derivative and rest of equation can be assumed to be zero.
`a+b+c+d+e+h=0→(i)`
`bDeltax+2cDeltax+3dDeltax+4eDeltax+5hDeltax=0->(ii)`
`{bDeltax^2}/2+{4cDeltax^2}/2+{9dDeltax^2}/2+{16eDeltax^2}/2+{25hDeltax^2}/2=1->(iii)`
`{bDeltax^3}/6+{8cDeltax^3}/6+{27dDeltax^3}/6+{64eDeltax^3}/6+{125hDeltax^3}/6=0->(iv)`
`{bDeltax^4}/24+{16cDeltax^4}/24+{81dDeltax^4}/24+{256eDeltax^4}/24+{625hDeltax^4}/24=0->(v)`
`{bDeltax^5}/120+{32cDeltax^5}/120+{243dDeltax^5}/120+{1024eDeltax^5}/120+{3125hDeltax^5}/120=0->(vi)`
Now, writting equation in matrix form, we get
AX=B
`[[1,1,1,1,1,1],[0,1,2,3,4,5],[0,1,4,9,16,25],[0,1,8,27,64,125],[0,1,16,81,256,625],[0,1,32,243,1024,3125]][[a],[b],[c],[d],[e],[h]]=[[0],[0],[2],[0],[0],[0]]`
solving the matrix equation, we get
`[[a],[b],[c],[d],[e],[h]]=[[45/12],[-154/12],[214/12],[-156/12],[61/12],[-10/12]]`
Substituting these value, the forth order approximation for second derivative can be obtained,
`(∂^2 f)/(∂^2 x)={45f(i)-154f(i+1)+214f(i+2)-156f(i+3)+61f(i+4)-10f(i+5)}/{12Deltax^2}`
Skewed Left-Hand Side Scheme
Stencil used for the forth order approximation for skewed left-hand side scheme.
The forth order skewed left-hand side scheme approximation for the second derivative of f is given by
`(∂^2 f)/(∂^2 x)=af(i)+bf(i-1)+cf(i-2)+df(i-3)+ef(i-4)+hf(i-5)`
The coefficent of Taylor series is enlisted in Taylor\'s table.
In the above Taylor\'s table, higher order derivatives are ignored as there only 6 unknown and we need 6 equation. The equation formed from the coefficent of `f^{\'\'}` can be assumed to be 1 as we need the approximation of second order derivative and rest of equation can be assumed to be zero.
`a+b+c+d+e+h=0→(i)`
`-bDeltax-2cDeltax-3dDeltax-4eDeltax-5hDeltax=0->(ii)`
`{bDeltax^2}/2+{4cDeltax^2}/2+{9dDeltax^2}/2+{16eDeltax^2}/2+{25hDeltax^2}/2=1->(iii)`
`-{bDeltax^3}/6-{8cDeltax^3}/6-{27dDeltax^3}/6-{64eDeltax^3}/6-{125hDeltax^3}/6=0->(iv)`
`{bDeltax^4}/24+{16cDeltax^4}/24+{81dDeltax^4}/24+{256eDeltax^4}/24+{625hDeltax^4}/24=0->(v)`
`-{bDeltax^5}/120-{32cDeltax^5}/120-{243dDeltax^5}/120-{1024eDeltax^5}/120-{3125hDeltax^5}/120=0->(vi)`
Now, writting equation in matrix form, we get
AX=B
`[[1,1,1,1,1,1],[0,1,2,3,4,5],[0,1,4,9,16,25],[0,1,8,27,64,125],[0,1,16,81,256,625],[0,1,32,243,1024,3125]][[a],[b],[c],[d],[e],[h]]=[[0],[0],[2],[0],[0],[0]]`
solving the matrix equation, we get
`[[a],[b],[c],[d],[e],[h]]=[[45/12],[-154/12],[214/12],[-156/12],[61/12],[-10/12]]`
Substituting these value, the forth order approximation for second derivative can be obtained,
`(∂^2 f)/(∂^2 x)={-10f(i-5)+61f(i-4)-156f(i-3)+214f(i-2)-154f(i-1)+45f(i)}/{12Deltax^2}`
Matlab code for calculating error for all three method of forth order approximation
clear all;
close all;
clc;
x=pi/3;
%array of dx
dx=linspace(pi/40,pi/4000,20);
val=zeros(6,3);
error=zeros(20,3);
central_diff=zeros(20,1);
skewed_right=zeros(20,1);
skewed_left=zeros(20,1);
% Analytical derivative calcuation at x=pi/3
first_derivative=exp(x)*(cos(x)-sin(x));
second_derivative=-2*exp(x)*sin(x);
for k=1:length(dx)
for i=1:5
val(i,1)=given_function(x-(i-3)*dx(k));
end
for j=0:5
val(j+1,2)=given_function(x+(j*dx(k)));
val(j+1,3)=given_function(x-((5-j)*dx(k)));
end
central_diff(k,1)=(-val(1,1)+16*val(2,1)-30*val(3,1)+16*val(4,1)-...
val(5,1))/(12*(dx(k)^2));
skewed_right(k,1)=(45*val(1,2)-154*val(2,2)+214*val(3,2)-156*val(4,2)+...
61*val(5,2)-10*val(6,2))/(12*(dx(k)^2));
skewed_left(k,1)=(-10*val(1,3)+61*val(2,3)-156*val(3,3)+214*val(4,3)-...
154*val(5,3)+45*val(6,3))/(12*(dx(k)^2));
error(k,1)=abs(second_derivative-central_diff(k,1));
error(k,2)=abs(second_derivative-skewed_right(k,1));
error(k,3)=abs(second_derivative-skewed_left(k,1));
end
figure
loglog(dx,error(:,1),\'b\',dx,error(:,2),\'g\',dx,error(:,3),\'r\')
xlabel(\'dx\');
ylabel(\'errror\');
legend(\'central difference\',\'skewed right\',\'skewed left\');
function used to calculate value of function at different point
function[out]=given_function(a)
out=exp(a)*cos(a);
end
Results
From graph, We can infer that central difference scheme provides more accurate result than skewed right-hand side and skewed left-hand side scheme. Central difference method is equivalent to the average of forward and backward difference method when the data points are equally spaced. It consider data points on either side of given point which helps know the function behaviour on either side of neighbourhood. Skewed right-hand and skewed left-hand side gives almost similar error.
Importance of Skewed Scheme
Function is not always defined on either side of point such as boundary points,undefined points etc.So, we cannot apply central difference scheme in such case. If fuction is defined only on left-hand side or right-hand side then Skewed left-hand side or skewed right-hand side scheme is used accordingly.