All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM To derive the fourth order approximations of a second order derivative using central differencing scheme, skewed right sided difference and skewed left sided difference with the help of Taylor table method and to compare the analytical derivative with obtained values for the given function. OBJECTIVE …
Manu Mathai
updated on 25 Jan 2023
AIM
To derive the fourth order approximations of a second order derivative using central differencing scheme, skewed right sided difference and skewed left sided difference with the help of Taylor table method and to compare the analytical derivative with obtained values for the given function.
OBJECTIVE
INTRODUCTION
In this challenge we will be dealing with Taylor Table method for the approximation. Taylor table is a general method for choosing the coefficients of a finite difference formula to ensure the highest possible order of accuracy. "Taylor Table" will determine the coefficients of the terms which minimizes the Taylor series error. It will also determine the Taylor series error and the order of accuracy of the method.
THEORY
Taylor series
The Taylor series of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor series are equal near this point.
f(x)=f(a)+f′(a)1!(x-a)+f′′(a)2!(x-a)2+f′′′(a)3!(x-a)3+...
f(x+a)=f(x)+f′(x)1!(a)+f′′(x)2!(a)2+f′′′(x)3!(a)3+...
As the degree of the Taylor polynomial rises, it approaches the correct function. This image shows sin x and its Taylor approximations by polynomials of degree 1, 3, 5, 7, 9, 11, and 13 at x = 0.
Approximations
We can use the first few terms of a Taylor Series to get an approximate value for a function.
Here we show better and better approximations for cos(x). The red line is cos(x), the blue is the approximation.
Deriving the 4th order approximations of the second-order derivative
Let's consider a numerical stencile with a set of grid points as shown in the fig below
right-sided difference
left -sided difference
Above shown both numerical stencils are Skewed 2nd order right & left -sided difference scheme for fourth order approximation.
central-difference
And this is symmetric central difference for 4th order opproximation
DERIVATION
Define the no.of nodes & the coefficients to find:
for central difference approximation we use
Number of nodes= P +Q - 1
P = Order of the approximation = 4
Q = Order of the derivative = 2
Number of nodes= 4 +2 – 1 = 5
So we will find up to 5 nodes for 2nd derivative of the 4th order approximation central difference approximation.
Since we’re deriving using central difference; our numerical stencil will look like.
Here, we’re computing 4th order approximation at point (i), where we take information from the four-point surrounding (i); i.e. we’re going to take two points on the left of (i) and two points on the right of (i). Let those points be (i-2), (i-1), (i+1), and (i+2) and the distance between each of them is (Δx). Our numerical stencil will look like as shown in the above figure.
Based on the above stencil our hypothesis equation will be:-
∂2f∂x2=af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2).........(1)
In order to find the values of coefficient(a,b,c,d,e), we’re going to use the Taylor table method. Writing Taylor series expansion for each term of equation (1) as:-
(a)f(i-2)=(a)f(i)-(a)f′(i)(2)Δx1!+(a)f′′(i)(2Δx)22!-(a)f′′′(i)(2Δx)33!+(a)f′′′′(i)(2Δx)44!-(a)f′′′′′(i)(2Δx)55!+(a)f′′′′′′(i)(2Δx)66!+....
(b)f(i-1)=(b)f(i)-(b)f′(i)Δx1!+(b)f′′(i)(Δx)22!-(b)f′′′(i)(Δx)33!+(b)f′′′′(i)(Δx)44!-(b)f′′′′′(i)(Δx)55!+(b)f′′′′′′(i)(Δx)66!+....
(c)f(i)=(c)f(i)
(d)f(i+1)=(d)f(i)-(d)f′(i)Δx1!+(d)f′′(i)(Δx)22!-(d)f′′′(i)(Δx)33!+(d)f′′′′(i)(Δx)44!-(d)f′′′′′(i)(Δx)55!+(d)f′′′′′′(i)(Δx)66!+....
(e)f(i+2)=(e)f(i)-(e)f′(i)2Δx1!+(e)f′′(i)(2Δx)22!-(e)f′′′(i)(2Δx)33!+(e)f′′′′(i)(2Δx)44!-(e)f′′′′′(i)(2Δx)55!+(e)f′′′′′′(i)(2Δx)66!+....
By arranging the above Taylor series expansions in Taylor table; we get:-
Note: Only for the first five terms we assume our hypothesis. That’s why we can’t say about the last two terms.
Here we have five unknowns, so, we have to solve five equations and get values of coefficients (a,b,c,d,e). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of `f''(i) is equal to 1, and f(i), f′(i), f′'(i), f′''(i), f′'''(i) are equal to 0; because we want to calculate the second-order derivative, f′'(i).
a+b+c+d+e=0
-2a-b+0+d+2e=0
4a2+(b2)+0+d2+4e2=1
-8a6-b6+0+d6+8e6=0
16a24-b24+0+d24+16e24=1
we can easily find out the coefficient values if we convers the above eq's into a matrix form :
AX=B
X=[11111-2-10122120122-86-1601686162412401241624]
X=[[a],[b],[c],[d],[e]]B=[[0],[0],[1],[0],[0]]`
X=A-1⋅B
X=[abcde]=[-0.083331.3333-2.50001.3333-0.08333]
Using mat lab we will solve the equation
A=[1, 1, 1, 1, 1;-2, -1, 0, 1, 2;4/2, 1/2, 0, 1/2, 4/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]
X=A^-1*B
Substitute the values of X matrix in equation and find the second derivative using central difference method.
Here, we observed that a= -0.0833; b=1.3333; c=-2.5; d=1.3333; e= -0.8333;
a=e;b=d;
Substitute in the table for fv(i)dx5 and we find that their sum of coefficient = 0;
After that, the term is fvi(i)dx6
Divide fvi(i)dx6, we get the coefficient in the order of dx4 . We are neglecting that terms, so we can say that our approximation is fourth order accurate.
2)Using Skewed Right-Sided Difference:
Define the no.of nodes & the coefficients to find:
for one sided / skewed schemes approximation we use
Number of nodes= P +Q
P = Order of the approximation = 4
Q = Order of the derivative = 2
Number of nodes= 4 +2 = 6
So we will find up to 6 nodes for 2nd derivative of the 4th order approximation for one sided / skewed schemes approximation.
To derive 4th order skewed right-sided difference at point (i) of function. Since we’re using the skewed right-sided method, here we have to define five points on the right of (i). Let those points be (i+1), (i+2), (i+3), (i+4), and (i+5); with a spacing of Δx each.
According to the above stencil, our hypothesis equation will be:
∂2f∂x2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)
In order to find the values of coefficients (a,b,c,d,e,g), we’re going to use the Taylor table method.
Writing Taylor series expansion for each term of equation as:-
(a)f(i)=(a)f(i)
(b)f(i+1)=(b)f(i)+(b)f′(i)Δx1!+(b)f′′(i)(Δx)22!+(b)f′′′(i)(Δx)33!+(b)f′′′′(i)(Δx)44!+(b)f′′′′′(i)(Δx)55!+(b)f′′′′′′(i)(Δx)66!+....
(c)f(i+2)=(c)f(i)+(c)f′(i)2Δx1!+(c)f′′(i)(Δx)22!+(c)f′′′(i)(2Δx)33!+(c)f′′′′(i)(2Δx)44!+(c)f′′′′′(i)(2Δx)55!+(c)f′′′′′′(i)(2Δx)66!+....
(d)f(i+3)=(d)f(i)+(d)f′(i)3Δx1!+(d)f′′(i)(3Δx)22!+(d)f′′′(i)(3Δx)33!+(d)f′′′′(i)(3Δx)44!+(d)f′′′′′(i)(3Δx)55!+(d)f′′′′′′(i)(3Δx)66!+....
(e)f(i+4)=(e)f(i)+(e)f′(i)4Δx1!+(e)f′′(i)(4Δx)22!+(e)f′′′(i)(4Δx)33!+(e)f′′′′(i)(4Δx)44!+(e)f′′′′′(i)(4Δx)55!+(e)f′′′′′′(i)(4Δx)66!+....
(g)f(i+5)=(g)f(i)+(g)f′(i)5Δx1!+(g)f′′(i)(5Δx)22!+(g)f′′′(i)(5Δx)33!+(g)f′′′′(i)(5Δx)44!+(g)f′′′′′(i)(5Δx)55!+(g)f′′′′′′(i)(5Δx)66!+....
By arranging the above Taylor series expansions in Taylor table; we get:-
Only for the first six terms, we assume our hypothesis. That’s why we can’t say about the last term.
Here we have six unknowns, so, we have to solve six equations and get values of coefficients (a,b,c,d,e,g). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of f′'(i) is equal to 1, and f(i), f′(i), f′'(i), f′''(i), f′'''(i), f'''''(i) is equal to 0; because we want to calculate the second-order derivative, f''(i).
Therefore, the six equations are:-
a+b+c+d+e+g=0
0+b+2c+3d+4e+5g=0
0+b2+4c2+9d2+16e2+25g2=1
0+b6+8c6+27d6+64e6+125g6=0
0+b24+16c24+81d24+256e24+625g24=0
0+b120+32c120+243d120+1024e120+3125g120=0
we can easily find out the coefficient values if we convers the above eq's into a matrix form :
AX=B
X=[1111110123450124292162252016862766461256012416248124256246252401120321202431201024120312524]
X=[abcdeg]B=[001000]
X=A-1⋅B
X=[abcdeg]=[3.7500-12.833317.8333-13.00005.0833-0.8333]
Using mat lab we will solve the equation
A=[1 1 1 1 1 1;0 1 2 3 4 5;0 1/2 4/2 9/2 16/2 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]
B=[0;0;1;0;0;0]
X=inv(A)*B
Substitute the values of X matrix in equation and find the second derivative using central difference method.
Here, we observed that a=3.75; b=-12.8333; c=17.8333; d=-13; e=5.0833; g=-0.8333;
We find the coefficient, upto the termfv(i)dx5
Divide fvi(i)dx6, we get the coefficient in the order of dx4 . We are neglecting that terms, so we can say that our approximation is fourth order accurate.
3)Using Skewed Left-Sided Difference:
Define the no.of nodes & the coefficients to find:
for one sided / skewed schemes approximation we use
Number of nodes= P +Q
P = Order of the approximation = 4
Q = Order of the derivative = 2
Number of nodes= 4 +2 = 6
So we will find up to 6 nodes for 2nd derivative of the 4th order approximation for one sided / skewed schemes approximation.
To derive 4th order skewed left-sided difference at point (i) of function. Since we’re using the skewed left-sided method, here we have to define five points on the left of (i). Let those points be (i-1), (i-2), (i-3), (i-4), and (i-5); with a spacing of Δx^2 each.
According to the above stencil, our hypothesis equation will be:
∂2f∂x2=af(i)+bf(i-1)+cf(i-2)+df(i-3)+ef(i-4)+gf(i-5)
To find the values of coefficients (a,b,c,d,e,g), we’re going to use the Taylor table method.
Writing Taylor series expansion for each term of equation as:-
(a)f(i-5)=(a)f(i)-(a)f′(i)5Δx1!+(a)f′′(i)(5Δx)22!-(a)f′′′(i)(5Δx)33!+(a)f′′′′(i)(5Δx)44!-(a)f′′′′′(i)(5Δx)55!+(a)f′′′′′′(i)(5Δx)66!+....
(b)f(i-4)=(b)f(i)-(b)f′(i)4Δx1!+(b)f′′(i)(4Δx)22!-(b)f′′′(i)(4Δx)33!+(b)f′′′′(i)(4Δx)44!-(b)f′′′′′(i)(4Δx)55!+(b)f′′′′′′(i)(4Δx)66!+....
(c)f(i-3)=(c)f(i)-(c)f′(i)3Δx1!+(c)f′′(i)(3Δx)22!-(c)f′′′(i)(3Δx)33!+(c)f′′′′(i)(3Δx)44!-(c)f′′′′′(i)(3Δx)55!+(c)f′′′′′′(i)(3Δx)66!+....
(d)f(i-2)=(d)f(i)-(d)f′(i)2Δx1!+(d)f′′(i)(2Δx)22!-(d)f′′′(i)(2Δx)33!+(d)f′′′′(i)(2Δx)44!-(d)f′′′′′(i)(2Δx)55!+(d)f′′′′′′(i)(2Δx)66!+....
(e)f(i-1)=(e)f(i)-(e)f′(i)3Δx1!+(e)f′′(i)(3Δx)22!-(e)f′′′(i)(3Δx)33!+(e)f′′′′(i)(3Δx)44!-(e)f′′′′′(i)(3Δx)55!+(e)f′′′′′′(i)(3Δx)66!+....
(g)f(i)=(g)f(i)
By arranging the above Taylor series expansions in Taylor table; we get:-
Only for the first six terms, we assume our hypothesis. That’s why we can’t say about the last term.
Here we have six unknowns, so, we have to solve six equations and get values of coefficients (a,b,c,d,e,g). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of f′'(i) is equal to 1, and f(i), f′(i), f′'(i), f′''(i), f′'''(i), f'''''(i) is equal to 0; because we want to calculate the second-order derivative, f''(i).
Therefore, the six equations are:-
a+b+c+d+e+g=0
-5a-4b-3c-2d-e+0=0
25a2+8b+9c2+2d+e2+0=1
-125a6-64b6-27c6-8d6-e6+0=0
625a24+256b24+81c24+16d24+e24+0=0
-3125a120-1024b120-243c120-32d120-e120+0=0
we can easily find out the coefficient values if we convers the above eq's into a matrix form :
AX=B
X=[111111-5-4-3-2-102521629242120-1256-646-276-86-1606252425624812416241240-3125120-1024120-243120-32120-11200]
X=[abcdeg]B=[001000]
X=A-1⋅B
X=[abcdeg]=[3.7500-12.833317.8333-13.00005.0833-0.8333]
Using mat lab we will solve the equation
A=[1 1 1 1 1 1;0 1 2 3 4 5;0 1/2 4/2 9/2 16/2 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]
B=[0;0;1;0;0;0]
x_r=inv(A)*B
Substitute the values of X matrix in equation and find the second derivative using central difference method.
Here, we observed that a=3.75; b=-12.8333; c=17.8333; d=-13; e=5.0833; g=-0.8333;
We find the coefficient, upto the termfv(i)dx5
Divide fvi(i)dx6, we get the coefficient in the order of dx4 . We are neglecting that terms, so we can say that our approximation is fourth order accurate.
we have rewrite the equations here ;
central difference approximation :
∂2f∂x2=a⋅f(x-2dx)+b⋅f(x-dx)+c⋅f(x)+d⋅f(x+dx)+e⋅f(x+2dx)Δx2
skewed forward difference approximation :
∂2f∂x2=a⋅f(x)+b⋅f(x+dx)+c⋅f(x+2dx)+d⋅f(x+3dx)+e⋅f(x+4dx)+g⋅f(x+5dx)Δx2
skewed backward difference approximation :
∂2f∂x2=a⋅f(x)+b⋅f(x-dx)+c⋅f(x-2dx)+d⋅f(x-3dx)+e⋅f(x-4dx)+g⋅f(x-5dx)Δx2
FUNCTION CODE:
CENTRAL DIFFERENCE APPROXIMATION
function central_diff_error=central_difference_approximation(x,dx)
%function=exp(x)*cos(x)
%f ''(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);
%numerical derivative
a=-0.083333;
b=1.333333;
c=-2.500000;
d=1.333333;
e=-.083333;
%central_diff_approx=(a*f(x-2*dx)+b*f(x-dx)+c*f(x)+d*f(x+dx)+e*f(x+2*dx))/(dx^2)
central_diff_approx=(a*(exp(x-2*dx)*cos(x-2*dx))+b*(exp(x-dx)*cos(x-dx))+c*(exp(x)*cos(x))+d*(exp(x+dx)*cos(x+dx))+e*(exp(x+2*dx)*cos(x+2*dx)))/(dx^2);
central_diff_error=abs(central_diff_approx-analytical_derivative)
end
BACKWARD DIFFERENCE APPROXIMATION
function skewed_backward_error=backward_difference_approximation(x,dx)
%function=exp(x)*cos(x)
%f ''(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);
%numerical derivative
a=-0.83333;
b=5.08333;
c=-13.00000;
d=17.83333;
e=-12.83333;
g=3.750000;
% skewed left sided approx=(a*f(x-5*dx)+b*f(x-4*dx)+c*f(x-3*dx)+d*f(x-2*dx)+e*f(x-dx)+g*f(x))/(dx^2)
skewed_backward_approx=(a*(exp(x-5*dx)*cos(x-5*dx))+b*(exp(x-4*dx)*cos(x-4*dx))+c*(exp(x-3*dx)*cos(x-3*dx))+d*(exp(x-2*dx)*cos(x-2*dx))+e*(exp(x-dx)*cos(x-dx))+g*(exp(x)*cos(x)))/(dx^2);
skewed_backward_error=abs(skewed_backward_approx-analytical_derivative);
end
FORWARD DIFFERENCE APPROXIMATION
function skewed_forward_error=forward_difference_approximation(x,dx)
%function=exp(x)*cos(x)
%f ''(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);
%numerical derivative
a=3.75000;
b=-12.83333;
c=17.83333;
d=-13.00000;
e=5.08333;
g=-0.83333;
%skewed rightsided approx=a*f(x)+b*f(x+dx)+c*f(x+2*dx)+d*f(x+3*dx)+e*f(x+4*dx)+g*f(x+5*dx)
skewed_forward_approx=(a*(exp(x)*cos(x))+b*(exp(x+dx)*cos(x+dx))+c*(exp(x+2*dx)*cos(x+2*dx))+d*(exp(x+3*dx)*cos(x+3*dx))+e*(exp(x+4*dx)*cos(x+4*dx))+g*(exp(x+5*dx)*cos(x+5*dx)))/(dx^2);
skewed_forward_error=abs(skewed_forward_approx-analytical_derivative);
end
MAIN CODE
clear all
close all
clc
x=pi/3;
dx=linspace(pi/4,pi/40000,40);
for i=1:length(dx)
central_diff_error(i)=central_difference_approximation(x,dx(i));
skewed_backward_error(i)=backward_difference_approximation(x,dx(i));
skewed_forward_error(i)=forward_difference_approximation(x,dx(i));
end
figure(1)
plot(dx,central_diff_error,"Color",'r','LineWidth',2)
hold on
plot(dx,skewed_backward_error,"Color",'b','LineWidth',2)
plot(dx,skewed_forward_error,"Color",'g','LineWidth',2)
legend('Central Difference Approximation','Backward Difference Approximation','Forward Difference Approximation')
grid on
xlabel('dx')
ylabel('error')
figure(2)
loglog(dx,central_diff_error,'color','r','linewidth',2)
hold on
loglog(dx,skewed_backward_error,'color','b','LineWidth',2)
loglog(dx,skewed_forward_error,'color','g','linewidth',2)
legend('Central Difference Approximation','Backward Difference Approximation','Forward Difference Approximation')
grid on
xlabel('dx')
ylabel('error')
Explanation
RESULT
From the above plot we can conclude that cemtral difference scheme has lesser error with decreasing dx as compared to the skewed right sided and skewed left sided schemes.
CD uses information from both the sides from the point of consideration to give approximative and accurate values.
As the left and right skewed difference methods uses data only from one side of point of interest it gives less approximative and accurate values about the point.
The 4th order approximations of the second-order derivative of Central difference , Skewed right-sided difference, Skewed left-sided difference and the program in Matlab to evaluate the second-order derivative of the analytical function exp(x)*cos(x) and compare it with the 3 numerical approximations that are derived are successfully completed.
1.why a skewed scheme is useful?
Skewed scheme is useful when there aren't sufficient information available, in such cases the numerical stencil might not be symmetric. Thus we use skewed scheme.
2.What can a skewed scheme do that a CD scheme cannot?
Since there are no boundaries or sufficient information available CD scheme cannot be used to find the value at the specified point thus we use skewed scheme in place of CD scheme even though CD scheme is more accurate than the skewed scheme and has lesser error as compared to skewed scheme.
CONCLUSION
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: Flow over a backward facing step
AIM: To run the simulation of Flow over a Backward facing step with three different base mesh sizes with help of using Converge Studio, Cygwin and Paraview and camparing the parameters. OBJECTIVE:- . Run 3 simulation . with 3 different base mesh sizes are 1. dx = 2e-3m dy = 2e-3m dz = 2e-3m …
11 Sep 2023 08:35 AM IST
Project 2 - 3D CFD modelling of Air cooling system and liquid cooling system for battery thermal management
1. Comparative study of thermal performance of air-cooled and liquid-cooled battery modules:- Air-cooled module:- The temperature distribution over the module surface with the air-cooling system at the end of the discharge process. The flow rate and temperature of the air at the inlet of the cooling system are 3 L/s and…
11 Sep 2023 08:25 AM IST
Week 1: Channel flow simulation using CONVERGE CFD
Introduction: Channel flow is an internal flow in which the confining walls change the hydrodynamic structure of the flow from an arbitrary state at the channel inlet to a certain state at the outlet. The simplest illustration of internal flow is a laminar flow in a circular tube, while a turbulent flow in the rotor of…
01 Sep 2023 10:15 AM IST
Project 1 - 1d modelling of liquid cooling system
Problem Description: we have a cooling plate mounted with 2 modules, each containing multiple cells. The flow pattern indicates that water is used as the coolant, flowing from a tank of limited capacity. The goal is to analyze the thermal behavior of the system, including plotting the top and bottom module temperatures,…
01 Sep 2023 10:03 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.