All Courses
All Courses
Derivation of 4th order numerical approximation for 2nd order derivative using Taylor table method and comparison of the differencing schemes AIM To derive the 4th order numerical approximation for 2nd order derivative of a given function using central, skewed right and skewed left differencing schemes and to write a program…
Ramkumar Venkatachalam
updated on 29 Jan 2022
Derivation of 4th order numerical approximation for 2nd order derivative using Taylor table method and comparison of the differencing schemes
To derive the 4th order numerical approximation for 2nd order derivative of a given function using central, skewed right and skewed left differencing schemes and to write a program in order to compare the analytical derivative with three numerical approximation derived.
Given function, f(x) = e^x/cos(x)
Analytical 2nd order derivative, f'’’(x) = -2*(e^x)*sin(x), x=pi/3 is the point of consideration where the function is being solved and dx ranges from pi/2000 to pi/20 with 20 interval points.
Taylor Table method
It’s a method in which the coefficients of the hypothesis function is calculated using Taylor series and expressed in tabular form. Each of these coefficients is then used for deriving the equation for numerical approximation of the derivative. Three types of differencing scheme are used such as central, skewed right and skewed left differencing scheme. Also the hypothesis function changes as per the differencing scheme used.
According to the aim, the Taylor Table method is used here to derive the 4th order numerical approximation for 2nd order derivative of a given function using central, skewed right and skewed left differencing schemes.
Skewed right differencing scheme
It is basically forward differencing scheme in which the derivative is calculated using the information from the point on right side of the point of consideration.
Skewed left differencing scheme
It is basically backward differencing scheme in which the derivative is calculated using the information from the point on left side of the point of consideration.
Central differencing scheme
It’s a scheme in which the derivative is calculated using the information from the very next point on both sides of the point of consideration. It is always used for approximation of even number order.
Number of points (P)
Number of points depends on the order of numerical approximation (n) and order of derivative (m).
For,
Skewed differencing scheme, P = m + n
Central differencing scheme, P = m + n - 1
Error is equal to the difference in numerical and analytical derivative.
3. OBJECTIVES & PROCEDURE
The main objective of the challenge is to understand the Taylor table method and to derive the 4th order numerical approximation for 2nd order derivative of a given function using central, skewed right and skewed left differencing schemes.
4. PROGRAM
Programming language used – Octave 5.1.1
Program
-------------------------------------------------------------------------------------
MAIN PROGRAM
-------------------------------------------------------------------------------------
x = pi/3;
dx = linspace(pi/2000,pi/20,20);
for i = 1:length(dx)
Central_differencing_scheme(i) = Taylor_Central(x,dx(i));
Skewed_Right_sided_differencing_scheme(i) = Taylor_Right(x,dx(i));
Skewed_Left_sided_differencing_scheme(i) = Taylor_Left(x,dx(i));
end
figure(1)
plot(dx,Central_differencing_scheme,'*')
hold on
plot(dx,Skewed_Right_sided_differencing_scheme,'*')
hold on
plot(dx,Skewed_Left_sided_differencing_scheme,'*')
title('Comparison of Differencing Schemes - Central differencing Vs Skewed Left Vs Skewed Right')
xlabel('dx','Fontsize',18)
ylabel('Absolute error','Fontsize',18)
legend('Central differencing scheme','Skewed Right sided differencing scheme','Skewed Left sided differencing scheme')
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
FUNCTION PROGRAM
-------------------------------------------------------------------------------------
TAYLOR_CENTRAL
function out = Taylor_Central(x,dx)
Matrix_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];
Matrix_B = [0 ; 0 ; 1 ; 0 ; 0];
X = Matrix_AMatrix_B;
% Given function f(x)= (e^x)*cos(x);
% Analytical second order derivative for the given function f''(x) = -2*(e^x)*sin(x);
% Computing Analytical second order derivative at x = pi/3;
Analytical_derivative = -2*(e^x)*sin(x);
% Central differencing scheme = (-0.083333*f(x-2*dx)+ 1.333333*f(x-dx)-2.500000*f(x)+1.333333*f(x+dx)-0.083333*f(x+2*dx))/(dx^2);
Central_differencing_scheme = ((X(1)*e^(x-2*dx)*cos(x-2*dx))+(X(2)*e^(x-dx)*cos(x-dx))+(X(3)*e^x*cos(x))+(X(4)*e^(x+dx)*cos(x+dx))+(X(5)*e^(x+2*dx)*cos(x+2*dx)))/(dx^2);
% Second Order Central differencing scheme Error
out = abs (Analytical_derivative - Central_differencing_scheme);
end
---------------------------------------------------------------------------------------
TAYLOR_SKEWED_RIGHT
function out = Taylor_Right(x,dx)
Matrix_A = [1 1 1 1 1 1; 0 1 2 3 4 5; 0 1/2 2 9/2 8 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];
Matrix_B = [0 ; 0 ; 1 ; 0 ; 0; 0];
X = Matrix_AMatrix_B;
% Given function f(x)= (e^x)*cos(x);
% Analytical second order derivative for the given function f''(x) = -2*(e^x)*sin(x);
% Computing Analytical second order derivative at x = pi/3;
Analytical_derivative = -2*(e^x)*sin(x);
% Skewed Right sided differencing scheme = (3.75000*f(x)-12.83333*f(x+dx)+17.83333*f(x+2*dx)-13.00000*f(x+3*dx)+5.08333*f(x+4*dx)-0.83333*f(x+5*dx))/(dx^2);
Skewed_Right_sided_differencing_scheme=((X(1)*(e^x)*cos(x))+(X(2)*e^(x+dx)*cos(x+dx))+(X(3)*e^(x+2*dx)*cos(x+2*dx))+(X(4)*e^(x+3*dx)*cos(x+3*dx))+(X(5)*e^(x+4*dx)*cos(x+4*dx))+(X(6)*e^(x+5*dx)*cos(x+5*dx)))/(dx^2);
% Second Order Skewed right sided differencing scheme Error
out = abs (Analytical_derivative - Skewed_Right_sided_differencing_scheme);
end
-------------------------------------------------------------------------------------
TAYLOR_SKEWED_LEFT
function out = Taylor_Left(x,dx)
Matrix_A = [1 1 1 1 1 1; -5 -4 -3 -2 -1 0; 25/2 8 9/2 2 1/2 0; -125/6 -64/6 -27/6 -8/6 -1/6 0; 625/24 256/24 81/24 16/24 1/24 0; -3125/120 -1024/120 -243/120 -32/120 -1/120 0];
Matrix_B = [0 ; 0 ; 1 ; 0 ; 0; 0];
X = Matrix_AMatrix_B;
% Given function f(x)= (e^x)*cos(x);
% Analytical second order derivative for the given function f''(x) = -2*(e^x)*sin(x);
% Computing Analytical second order derivative at x = pi/3;
Analytical_derivative = -2*(e^x)*sin(x);
% Skewed Left sided differencing scheme = (-0.83333*f(x-5*dx)+5.08333*f(x-4*dx)-13.00000*f(x-3*dx)+17.83333*f(x-2*dx)-12.83333*f(x-dx)+3.75000*f(x))/(dx^2);;
Skewed_Left_sided_differencing_scheme = ((X(1)*e^(x-5*dx)*cos(x-5*dx))+(X(2)*e^(x-4*dx)*cos(x-4*dx))+(X(3)*e^(x-3*dx)*cos(x-3*dx))+(X(4)*e^(x-2*dx)*cos(x-2*dx))+(X(5)*e^(x-dx)*cos(x-dx))+(X(6)*(e^x)*cos(x)))/(dx^2);
% Second Order Skewed Left sided differencing scheme Error
out = abs (Analytical_derivative - Skewed_Left_sided_differencing_scheme);
end
-------------------------------------------------------------------------------------
5. RESULTS
Calculation
Graph
6. CONCLUSION
From the above graph, it can be clearly seen that the error obtained from central differencing scheme is minimal compared to Skewed Right and Left differencing scheme.
By using the Taylor table method we can calculate numerical approximation for any given order of derivative and differencing schemes.
But central differencing scheme cannot be used everywhere for better results, as the scheme has the requirement of information from both sides of the point of consideration.
So only skewed differencing schemes can be used if the solution is needed at the end nodes of the domain. It will be useful if the information needs to be taken from multiple points but from only one side of the point of consideration.
Finally the choice of differencing scheme depends on the direction of flow of information.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 3 Challenge : CFD meshing on Turbocharger
VOLUME MESHING ON A TURBOCHARGER USING ANSA (WEEK-3 CHALLENGE) AIM Our…
24 Jul 2022 06:35 PM IST
Week 2 Challenge : Surface meshing on a Pressure valve
…
10 Jul 2022 04:29 AM IST
Week 9: Project 1 - Surface preparation and Boundary Flagging (PFI)
SURFACE PREPARATION AND BOUNDARY FLAGGING OF IC ENGINE MODEL AND SETTING NO HYDRO SIMULATION USING CONVERGE CFD …
18 Jun 2022 05:56 PM IST
Week 8: Literature review - RANS derivation and analysis
LITERATURE REVIEW – REYNOLDS AVERAGED NAVIER STOKES DERIVATION AND ANALYSIS …
12 Jun 2022 04:58 PM IST
Related Courses
0 Hours of Content