Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
Objective:
To derive the 4th order approximation of a second order derivative for central difference and skewed left and right didded difference method using taylor table method and to compute analytical derive and write functionin matlab to find range of dx vs error.
Schemes:
1. Central difference
2.Skewed right sidded difference
3. skewed left sidded difference
1. Central difference:
P= order of accuracy
N= Number of nodes
Q= order of derivative
Equation:
N= P+Q-1
Q = 4th order approximation (4)
P = 2nd order derivative (2)
so nodes value is,
N =2+4-1 =5
N = 5
Derivative:
...................(1)
expand all terms:

Taylor series Table:
| dx^2 f'' (i) | f(i) | f(i)dx | f'(i)dx^2 | f''(i)dx^3 | f'''(i)dx^4 |
| a f(i-2) | a | -2a | 2a | -4a /3 | 2a/3 |
| 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 | 2e | 4e/3 | 2e/3 |
| sum of co-effecient | 0 | 0 | 1 | 0 | 0 |
Now, we apply martic formation:
A.X = B

x= 1/A . B (or) inv(A).B
Result of:

a= -0.0833 , b=1.333 , c= -2.5000 , d=1.333 , e = -0.0833 .................(2)
substitute value in eqn (1)

2.Skewed right sidded difference Scheme:
N= P+Q
nodes value is,
N =2+4 =6
N = 6
Derivative:
.............(3)
expand all terms:
Taylor series Table:
| dx^2 f'' (i) | f(i) | f(i)dx | f'(i)dx^2 | f''(i)dx^3 | f'''(i)dx^4 | f''''(i)dx^5 |
| a f(i) | a | 0 | 0 | 0 | 0 | 0 |
| b f(i+1) | b | b | b/2 | b/6 | b/24 | b/120 |
| c f(i+2) | c | 2c | 4c/2 | 8c/6 | 16c/24 | 32c/120 |
| d f(i+3) | d | 3d | 9d/2 | 27d/6 | 81d/24 | 243d/120 |
| e f(i+4) | e | 4e | 16e/2 | 32e/6 | 64e/24 | 256e/120 |
| g f(i+5) | g | 5g | 25g/2 | 125g/6 | 625g/24 | 3125g/120 |
| sum of co-effecient | 0 | 0 | 1 | 0 | 0 |
0 |
Now, we apply martic formation:
A.X = B

x= 1/A . B (or) inv(A).B

a= 3.7500 ; b = -12.8333 ; c = 17.8333 ; d = -13.0000 ; e = 5.0833 ; g = -0.8333
substitute value in eqn (3)

3.Skewed sidded difference Scheme:
N= P+Q
nodes value is,
N =2+4 =6
N = 6
Derivative:
.......(4)
expand all terms:

Taylor series Table:
| dx^2 f'' (i) | f(i) | f(i)dx | f'(i)dx^2 | f''(i)dx^3 | f'''(i)dx^4 | f''''(i)dx^5 |
| a f(i-5) | a | -5a | 25a/2 | -125a/6 | 625a/24 | -3125a/120 |
| b f(i-4) | b | -4b | 16b/2 | -64b/6 | 256b/24 | -1024b/120 |
| c f(i-3) | c | -3c | 9c/2 | -27c/6 | 81c/24 | -243c/120 |
| d f(i-2) | d | -2d | 4d/2 | -8d/6 | 16d/24 | -32d/120 |
| e f(i-1) | e | -e | -e/2 | e/6 | e/24 | -e/120 |
| g f(i) | g | 0 | 0 | 0 | 0 | 0 |
| sum of co-effecient | 0 | 0 | 1 | 0 | 0 | 0 |
Now, we apply martic formation:
A.X = B

x= 1/A . B (or) inv(A).B

a = -0.8333 ; b = 5.0833 ; c= -13.000 ; d = 17.8333 ; e = -12.8333 ;g = 3.7500
substitute value in eqn (4)

And, next we write code in matlab:
code:
clear all;
close all;
clc;
% x value
x = pi/3 ;
%dx
dx = linspace(pi/40 , pi/4000 , 20);
%loop
for i=1:length(dx)
central_differencing(i) = fourth_oder_Central_difference(x,dx(i));
Skewed_right_sided(i) = fourth_order_Skewed_right_sided_difference(x,dx(i));
Skewed_left_sided(i) = fourth_order_Skewed_left_sided_difference(x,dx(i));
end
%plotting(loglog)
loglog(dx,central_differencing,'b');
grid on
hold on
loglog(dx,Skewed_right_sided,'r');
hold on
loglog(dx,Skewed_left_sided,'g');
xlabel('range of dx');
ylabel('error')
title('range of dx vs error');
legend('central differencing','Skewed right sided','Skewed left sided')
% function code for all differencing scheme
%function code - central_differencing scheme
function central_differencing_error = fourth_oder_Central_difference(x,dx)
% analytical_equation:exp(x)*cos(x)
analytical_derivative = -2*exp(x)*cos(x);
%numerical derivative
central_differencing = ((((-0.08333)*(exp(x-(2*dx)))*(cos(x-(2*dx)))) + ((1.333)*(exp(x-dx)))*(cos(x-dx)))+((-2.500)*(exp(x)*cos(x)))+((1.333)*(exp(x+dx)))*(cos(x+dx))+((-0.08333)*(exp(x+(2*dx))))*(cos(x+(2*dx))))/(dx^2);
%error of central differencing
central_differencing_error= abs(central_differencing-analytical_derivative);
end
%function code - Skewed_right_sided_differencing scheme
function Skewed_right_sided_differencing_error = fourth_order_Skewed_right_sided_difference(x,dx)
% analytical_equation:exp(x)*cos(x)
analytical_derivative = -2*exp(x)*cos(x);
%numerical derivative
Skewed_right_sided= ((((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.0833)*(exp(x+(4*dx)))))*(cos(x+(4*dx))+((-0.8333)*(exp(x+(5*dx))))*(cos(x+(5*dx))))/(dx^2);
%error of Skewed_right_sided differencing
Skewed_right_sided_differencing_error= abs(Skewed_right_sided-analytical_derivative);
end
%function code - Skewed_left_sided_differencing scheme
function Skewed_left_differencing_error = fourth_order_Skewed_left_sided_difference(x,dx)
% analytical_equation:exp(x)*cos(x)
analytical_derivative = -2*exp(x)*cos(x);
%numerical derivative
Skewed_left_sided= (((-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.7500)*(exp(x)))*(cos(x)))/(dx^2);
%error of Skewed_left_sided differencing
Skewed_left_differencing_error= abs(Skewed_left_sided-analytical_derivative);
end
Result:
I have attached the plot file
Conclution:
here, we can find the plot of result , the central differencing scheme is very less of compared to other Skewed left sided differencing and Skewed right sided differencing scheme.
so therefore, Skewed left and right sided differencing scheme is better than cental difference scheme and give accurate value .
why a skewed scheme is useful?
skewed scheme is result data point value is always give accurate and statification result compared to cd method result.skewness of data helps us in creating better linear models. so skewed scheme useful.
What can a skewed scheme do that a CD scheme cannot?
because in boundary point cases , CDS is not take both side of points and cannot give accurate value, so we can choose skewed scheme.