Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
Aim:- To derive the fourth order approximations of a second order derivative using central differencing scheme, skewed right side difference and skewed left side difference with the help of taylor table method and to compare analytical derivative obtained.
SCHEMES:
CENTRAL DIFFERENCING
NO OF NODES:
The no of nodes = p+q-1;
Where p= order derivative & q= order of approximation
So nodes = 2 +4 -1 =5
DERIVATION
the linear equation obtained from above can be used in matrix inversion method
A.X=B
So, X= inv(A)*B
We then get coefficients data

a= -.0833, b=1.3333 , c= -2.5000, d= 1.3333 & e = -0.0833
substituting coefficients in equation we get,
`(del^2u)/(delx^2)=(-0.0833) f(i-2) +(1.3333)f(i-1) +(-2.5000)f(i) +(1.3333)f(i+1) +(-0.0833)f(i+2)`
SKEWED RIGHT HAND DIFFERENCE SCHEME
NO OF NODES:
N= p+q;
where p is order derivative & q is order of approximation
n= 2+4 =6
DERIVATION

Data obtained will solved using matrix
A.X=B
X= Inv(A)*B
we get coefficients value

a= 3.7500, b= -12.8333, c= 17.8333, d= -13.0000, e = 5.0833 & g=-0.8333
substituting in equation we get,
`(del^2u)/(delx^2)=(3.7500) f(i) +(-12.8333)f(i+1) +(17.8333)f(i+2) +(-13.0000)f(i+3) +(5.0833)f(i+4)+ (-0.8333)f(i+5)`
SKEWED LEFT HAND DIFFERENCE
NO OF NODES:
n= p+q
p is order of derivative and q is order of approximations.
n= 2+4=6
DERIVATION
Equation obtained from above is solved using matrix inversion method
A.X=B
X=inv(A)B
we get coefficients and we put tem in equation.
a= -.8333, b= 5.0833, c= -13.0000, d =17.8333, e = -12.8333 & g = 3.7500
Equation:
`(del^2u)/(delx^2)=(-0.8333) f(i-5) +(5.0833)f(i-4) +(-13.0000)f(i-3) +(17.8333)f(i-2) +(-12.8333)f(i-1)+ (3.7500)f(i)`
MAIN CODE
close all
clear all
clc
% value of x & dx
x= pi/3;
dx= linspace(pi/4,pi/4000,200);
% loop for calulating errors
for i= 1:length(dx)
Error_central_differencing(i)= fourth_central(x,dx(i));
Error_Right_skewed_differencing(i)= fourth_right_skewed(x,dx(i));
Error_Left_skewed_differencing(i)= fourth_left_skewed(x,dx(i));
end
%plotting Errors
figure(1)
loglog(dx,Error_central_differencing,'r<-','markersize',2)
hold on
loglog(dx,Error_Right_skewed_differencing,'b<-','markersize',2)
hold on
loglog(dx,Error_Left_skewed_differencing,'g->','markersize',2)
xlabel('Range of dx')
ylabel('Truncataion errors')
legend('Central Differencing','Right Skewed differencing','Left Skewed differencing','location','best')
CENTRAL FUNCTION
function Error_central_differencing= fourth_central(x,dx)
% analytic function = exp(x)*cos(x)
analytic_derivative= -2*(exp(x))*(sin(x));
% numerical derivative
central_differencing= (((-0.08333)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))+ ((1.33333)*((exp(x-dx))*(cos(x-dx)))) - ((2.5000)*((exp(x))*(cos(x))))+ ((1.33333)*((exp(x+dx))*(cos(x+dx))))- ((0.08333)*((exp(x+(2*dx)))*(cos(x+(2*dx))))))/(dx^2);
% Error
Error_central_differencing= abs(central_differencing - analytic_derivative);
end
RIGHT SKEWED FUNCTION
function Error_Right_skewed_differencing= fourth_right_skewed(x,dx)
% analytic function = exp(x)*cos(x)
analytic_derivative= -2*(exp(x))*(sin(x));
% numerical derivative
right_skewed= (((3.75000)*((exp(x))*(cos(x)))) -((12.8333)*((exp(x+dx))*(cos(x+dx))))+ ((17.8333)*((exp(x+(2*dx)))*(cos(x+(2*dx))))) -((13.000)*((exp(x+(3*dx)))*(cos(x+(3*dx)))))+ ((5.08333)*((exp(x+(4*dx)))*(cos(x+(4*dx))))) -((0.8333)*((exp(x+(5*dx)))*(cos(x+(5*dx))))))/(dx^2);
% Error
Error_Right_skewed_differencing= abs(right_skewed - analytic_derivative);
end
LEFT SKEWED FUNCTION
function Error_Left_skewed_differencing= fourth_left_skewed(x,dx)
% analytic function = exp(x)*cos(x)
analytic_derivative= -2*(exp(x))*(sin(x));
% numerical derivative
left_skewed= (((-0.8333)*((exp(x-(5*dx)))*(cos(x-(5*dx)))))+ ((5.0833)*((exp(x-(4*dx)))*(cos(x-(4*dx)))))- ((13.000)*((exp(x-(3*dx)))*(cos(x-(3*dx)))))+ ((17.8333)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))- ((12.8333)*((exp(x-dx))*(cos(x-dx))))+((3.75)*((exp(x))*(cos(x)))))/(dx^2);
% Error
Error_Left_skewed_differencing= abs(left_skewed - analytic_derivative);
end
RESULTS

CONCLUSION
As the plot shows the central scheme is more eefficient as it has less error compared to both skewed schemes as it uses information from both sides to give approximate and accurate result.
On the other hand skewed scheme is succesfull in places where there is no sufficient information on both sides eg, a case where we dont know previous points or either forward points we can use left handed skewed or right handed skewed accordingly in that case.