All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Derive the 4th order approximation of the second-order derivative using central difference scheme let f be the function whose second derivative is approximated at ith point using function values at (i-2), (i-1), i, (i+1), (i+2) points. let h be the distance between the consecutive points. let d2fdx2=a⋅fi−2+b⋅fi−1+c⋅fi+d⋅fi+1+e⋅fi+2+O(hn)…
Jaswanth Kalyan Kumar Alapati
updated on 13 Jul 2021
Derive the 4th order approximation of the second-order derivative using central difference scheme
let f be the function whose second derivative is approximated at ith point using function values at (i-2), (i-1), i, (i+1), (i+2) points. let h be the distance between the consecutive points.
let d2fdx2=a⋅fi−2+b⋅fi−1+c⋅fi+d⋅fi+1+e⋅fi+2+O(hn)
n is the order of the scheme and is to be determined.
By Taylor's series, fi+1=fi+(h1!)f'i+(h22!)f''i+(h33!)f'''i+.....
Applying the above series to fi−2,fi−1,andfi+2 and summing them appropriately gives
d2fdx2=(a+b+c+d+e)⋅fi+(−2ah−bh+dh+2eh)⋅f'i+(2ah2+bh22+dh22+2eh2)⋅f''i+......
On equating the corresponding terms of derivatives appropriately it gives
a+b+c+d+e=0
−2ah−bh+dh+2eh=0
2ah2+bh22+dh22+2eh2=1
−8ah36−bh36+dh36+8eh36=0
16ah424+bh424+dh424+16eh424=0
Solving for the coefficients gives a=−112h2,b=43h2,c=−52h2,d=43h2,ande=−112h2
substituting the above values gives n=4.
So d2fdx2=−fi−212+4fi−13−5fi2+4fi+13−fi+212h2+O(h4)
Thus the second derivative of a function using a central difference scheme (fourth-order) is derived using Taylor's table.
Following a similar approach to determine the second derivative using forward difference (right-sided) scheme.
let f be the function whose second derivative is approximated at ith using function values at i, (i+1), (i+2), (i+3), (i+4), and (i+5) points. let h be the distance between the consecutive points.
let d2fdx2=a⋅fi+b⋅fi+1+c⋅fi+2+d⋅fi+3+e⋅fi+4+g⋅fi+5+O(hn)
a, b, c, d, e, and g are constants to be determined.
Expanding the function values at (i+1), (i+2), (i+3), (i+4), and (i+5) using Taylor's series and summing them.
d2fdx2=(a+b+c+d+e+g)⋅fi+(bh+2ch+3dh+4eh+5gh)⋅f'i+(bh22+4ch22+9dh22+16eh22+25gh22)⋅f''i+......
On equating the corresponding coefficients of derivatives on both sides, it gives
a+b+c+d+e+g=0
bh+2ch+3dh+4eh+5gh=0
bh22+4ch22+9dh22+16eh22+25gh22=1
.
.
bh5120+32ch5120+243dh52+1024eh5120+3125gh5120=0
The above 6 equations are solved to get the 6 constants.
They are a=154h2,b=−776h2,c=1076h2,d=−13h2,e=6112h2,andg=−56h2
Substituting the above values gives n=4.
So d2fdx2=15fi4−77fi+16+107fi+26−13fi+3+61fi+412−5fi+56h2+O(h4)
Thus fourth-order right-sided difference scheme is derived.
Following a similar approach, a fourth-order left-sided difference scheme is derived.
So d2fdx2=15fi4−77fi−16+107fi−26−13fi−3+61fi−412−5fi−56h2+O(h4)
A function f for ex⋅cos(x) is created to calculate its values at different input values. It is as follows.
function y=f(x)
y=exp(x)*cos(x);
end
It is then used to calculate the second derivative for different dx values using various numerical schemes.
The MATLAB code is as follows.
close all
clear all
clc
% f=exp(x)*cos(x)
% Analytical derivative, f'=exp(x)*exp(x)*(-2*sin(x))
% let x=pi/4 and dx varies from pi/1000 to pi/10
x=pi/3;
dx=linspace(pi/4000,pi/10,20);
exact_value=exp(x)*(-2*sin(x));
% 1 row and 20 columns, each column for different value of dx
numerical_forward=zeros(1,20);
forward_error=zeros(1,20);
numerical_central=zeros(1,20);
central_error=zeros(1,20);
numerical_backward=zeros(1,20);
backward_error=zeros(1,20);
for i=1:length(dx)
numerical_forward(i)=((15/4)*f(x)-(77/6)*f(x+dx(i))+(107/6)*f(x+2*dx(i))-13*f(x+3*dx(i))+(61/12)*f(x+4*dx(i))-(5/6)*f(x+5*dx(i)))/(dx(i)^2);
forward_error(i)=abs(exact_value-numerical_forward(i));
numerical_central(i)=(-(1/12)*f(x-2*dx(i))+(4/3)*f(x-dx(i))-2.5*f(x)+(4/3)*f(x+dx(i))-(1/12)*f(x+2*dx(i)))/(dx(i)^2);
central_error(i)=abs(exact_value-numerical_central(i));
numerical_backward(i)=((15/4)*f(x)-(77/6)*f(x-dx(i))+(107/6)*f(x-2*dx(i))-13*f(x-3*dx(i))+(61/12)*f(x-4*dx(i))-(5/6)*f(x-5*dx(i)))/(dx(i)^2);
backward_error(i)=abs(exact_value-numerical_backward(i));
end
plot(dx,forward_error,dx,central_error,dx,backward_error);
legend('Forward','Central','Backward');
xlabel('Grid-length(dx)');
ylabel('Error');
title('Plot of error for different numerical schemes vs dx');
The generated plot is as follows.
In general, central difference schemes have better accuracy (or higher-order) than single-sided schemes, visible from the above plot where the central difference has less error than other schemes at all values of dx. But at boundaries, a central difference scheme can't be employed.
Single-sided schemes perform better in cases where the flow (or information) flows in a single particular direction.
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 1- Mixing Tee
This assignment aims to evaluate the mixing effectiveness of a Tee joint with two different outlet pipe lengths, namely small and long. The required Tee geometry is provided, and the interior volume for CFD analysis is extracted as shown below. Tee geometry with shorter outlet pipe: Extracted…
03 Sep 2022 08:13 PM IST
Week 12 - Validation studies of Symmetry BC vs Wedge BC in OpenFOAM vs Analytical H.P equation
Unlike in the previous assignment, where the simulation is performed using a transient solver icoFoam, the simulation is carried out using a steady-state solver simpleFoam since the emphasis is on the steady-state flow field. This assignment aims to compare the boundary conditions of Wedge and Symmetry…
11 Jan 2022 11:09 AM IST
Week 11 - Simulation of Flow through a pipe in OpenFoam
The following is the simulation of a laminar flow of an incompressible fluid through the pipe in OpenFoam. The following figure depicts the physical situation of the flow. For a laminar flow, the hydrodynamic length, Lh=0.06⋅D⋅ReD, where D is pipe diameter, and ReD is Reynolds number…
07 Jan 2022 10:13 AM IST
Week 9 - FVM Literature Review
Finite Volume Method (FVM) is a numerical technique for solving partial differential equations governing the phenomena. The method involves discretizing the domain into smaller volumes. These control volumes are connected by common faces. The governing equation in integral form is applied for all the control volumes followed…
26 Dec 2021 07:15 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.