All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
In this challenge, we are going to derive the 4th order approximations of the second-order derivative by the following methods. The methods we are going to use are: 1. Central Difference 2. Skewed right-sided difference 3. Skewed left-sided difference First, we use here is 1. Central Difference: Numerical stencil we will…
GAURAV KHARWADE
updated on 21 Oct 2019
In this challenge, we are going to derive the 4th order approximations of the second-order derivative by the following methods.
The methods we are going to use are:
1. Central Difference
2. Skewed right-sided difference
3. Skewed left-sided difference
First, we use here is
1. Central Difference:
Numerical stencil we will consider here is
(i−2)−−(i−1)−−(i)−−(i+1)−−(i+2)
2nd order derivative can be written as
d2u(dx)2=a⋅f(i−2)+b⋅f(i−1)+c⋅f(i)+d⋅f(i+1)+e⋅f(i+2)------equation 1
Taylor's Table we can compute is as
As we are dealing with five unknowns we have five equations to find the unknowns which can be done by using simple MATLAB code.
A=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣11111−2−10122120122−86−1601686162412401241624⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦
B=[00100]
X=A/B
After solving the values we will get is
a=-0.0833
b=1.3333
c=-2.5
d=1.3333
e=-0.0833
We can clearly see that a=e and b=d
Expansion of equation we have
by putting all the values of all variable in equation 1.
we can rewrite equation 1 as
d2u(dx)2=(−0.0833⋅f(i−2)+1.3333⋅f(i−1)+2.5⋅f(i)+1.3333⋅f(i+1)−0.0833⋅f(i+2)dx2)+O(x4)
where, O(x^4)- Truncation error of 4th order scheme
Above equation represents 4th order approximation scheme of 2nd order derivative by CENTRAL DIFFERENCE METHOD.
2. Skewed right-sided difference:
Numerical stencil we will consider here is
(i)−−−(i+1)−−−(i+2)−−−(i+3)−−−(i+4)
The equation we need to expand is
d2u(dx)2=aâ‹…f(i)+bâ‹…f(i+1)+câ‹…f(i+2)+dâ‹…f(i+3)+eâ‹…f(i+4)------equation 2
Taylor's table expansion will be as
we are going to find out five unknowns with five equations as
A=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣1111101214012212162016861664601241624812425624⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦
B=[00100]
X=A/B
the values for unknowns we wil get is
a=2.9167
b=-8.6667
c=9.5
d=-4.6667
e=0.9167
Put all above values in equation 2
d2u(dx)2=(2.9167⋅f(i)−8.6667⋅f(i+1)+9.5⋅f(i+2)−4.6667⋅f(i+3)+0.9167⋅f(i+4)dx2)+O(x4)
where, O(x^4)- Truncation error of 4th order scheme
The above equation represents the 4th order approximation scheme of 2nd order derivative by Skewed right-sided difference.
3. Skewed left-sided difference:
Numerical stencil we will consider here is
(i−4)−−−(i−3)−−−(i−2)−−−(i−1)−−−(i)
The equation we need to expand is
d2u(dx)2=a⋅f(i)+b⋅f(i−1)+c⋅f(i−2)+d⋅f(i−3)+e⋅f(i−4)------equation 3
Taylor\'s table expansion will be as
we are going to find out five unknowns with five equations as
A=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣111110−1−2−1−40122121620−16−86−16−64601241624812425624⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦
B=[00100]
X=A/B
the values for unknowns we wil get is
a=2.9167
b=-8.6667
c=9.5
d=-4.6667
e=0.9167
Put all above values in equation 2
d2u(dx)2=(2.9167⋅f(i)−8.6667⋅f(i−1)+9.5⋅f(i−2)−4.6667⋅f(i−3)+0.9167⋅f(i−4)dx2)+O(x4)
where, O(x^4)- Truncation error of 4th order scheme
The above equation represents the 4th order approximation scheme of 2nd order derivative by Skewed left-sided difference.
Function codes for each scheme are as follows to get the idea of the behavior of error for known values of x and dx.
%Function code for Central Difference:
function e1= CD_second_order_derivative(x,dx)
analytical_derivative=-exp(x)*2*sin(x);
a=exp(x-2*dx)*cos(x-2*dx);
b=exp(x-1*dx)*cos(x-1*dx);
c=exp(x)*cos(x);
d=exp(x+1*dx)*cos(x+1*dx);
e=exp(x+2*dx)*cos(x+2*dx);
% Central differencing for fourth-order approximation of 2nd Order
% derivative
central_differencing=(-0.08333*a+1.3333*b+2.5*c+1.3333*d-0.08333*e)/dx^2;
e1=abs(analytical_derivative-central_differencing);
end
%Function code for Skewed right-sided difference:
function e2= SRSD_second_order_derivative(x,dx)
analytical_derivative=-exp(x)*2*sin(x);
c=exp(x)*cos(x);
d=exp(x+1*dx)*cos(x+1*dx);
e=exp(x+2*dx)*cos(x+2*dx);
f=exp(x+3*dx)*cos(x+3*dx);
g=exp(x+4*dx)*cos(x+4*dx);
% Skewed Right side difference for fourth-order approximation of 2nd Order
% derivative
SRSD_differencing=(2.9167*c-8.6667*d+9.5*e-4.6667*f+0.9167*g)/dx^2;
e2=abs(analytical_derivative-SRSD_differencing);
end
%Function code for Skewed left-sided difference:
function e3= SLSD_second_order_derivative(x,dx)
analytical_derivative=-exp(x)*2*sin(x);
j=exp(x-4*dx)*cos(x-4*dx);
h=exp(x-3*dx)*cos(x-3*dx);
a=exp(x-2*dx)*cos(x-2*dx);
b=exp(x-1*dx)*cos(x-1*dx);
c=exp(x)*cos(x);
% Central differencing for fourth-order approximation of 2nd Order
% derivative
SLSD_differencing=(2.9167*c-8.6667*b+9.5*a-4.6667*h+0.9167*j)/dx^2;
e3=abs(analytical_derivative-SLSD_differencing);
end
Main Program file:
clear all
close all
clc
% function f(x)=exp(x)*cos(x)
% Double derivative of function f\"(x)= -exp(x)*2*sin(x)
% lets assume
x=pi/2;
dx=linspace(pi/4,pi/400,10);
% Analytical D.derivative of function is
analytical_derivative=-exp(x)*2*sin(x);
% For 4th order approximation
for i=1:length(dx)
j(i)=exp(x-4.*dx(i))*cos(x-4.*dx(i));
h(i)=exp(x-3.*dx(i))*cos(x-3.*dx(i));
a(i)=exp(x-2.*dx(i))*cos(x-2.*dx(i));
b(i)=exp(x-1.*dx(i))*cos(x-1.*dx(i));
c(i)=exp(x)*cos(x);
d(i)=exp(x+1.*dx(i))*cos(x+1.*dx(i));
e(i)=exp(x+2.*dx(i))*cos(x+2.*dx(i));
f(i)=exp(x+3.*dx(i))*cos(x+3.*dx(i));
g(i)=exp(x+4.*dx(i))*cos(x+4.*dx(i));
ERROR1(i)=CD_second_order_derivative(x,dx(i))
ERROR2(i)=SRSD_second_order_derivative(x,dx(i))
ERROR3(i)=SLSD_second_order_derivative(x,dx(i))
% FORWARD DIFFERENCING
forward_differencing=(c-2*d+e)/dx(i).^2;
ERROR_FDS(i)=abs(forward_differencing(i)-analytical_derivative)
% BACKWARD DIFFERENCING
backward_differencing=(c-2*b+a)/dx(i).^2;
ERROR_BDS(i)=abs(backward_differencing(i)-analytical_derivative)
end
figure(1)
loglog(dx,ERROR1,\'b\',\'linewidth\',1.5)
hold on
loglog(dx,ERROR2,\'r\',\'linewidth\',1.5)
hold on
loglog(dx,ERROR3,\'y\',\'linewidth\',1.5)
hold on
xlabel(\'dx\');
ylabel(\'Absolute Errors\');
title(\'Comparision between CD/SRSD/SLSD schemes of 4th order approximation of 2nd order derivative\')
legend(\'CD\',\'SRSD\',\'SLSD\');
figure(2)
loglog(dx,ERROR1,\'b\',\'linewidth\',1.5)
hold on
loglog(dx,ERROR2,\'r\',\'linewidth\',1.5)
hold on
loglog(dx,ERROR3,\'y\',\'linewidth\',1.5)
hold on
loglog(dx,ERROR_FDS,\'k--\',\'linewidth\',0.5)
hold on
loglog(dx,ERROR_BDS,\'k-o\',\'linewidth\',0.5)
hold on
xlabel(\'dx\');
ylabel(\'Absolute Errors\');
title(\'Comparision between FDS/BDS & CD/SRSD/SLSD schemes of 4th order approximatio of 2nd order derivative\')
legend(\'CD\',\'SRSD\',\'SLSD\',\'FDS\',\'BDS\');
The plots that we have is as below:
From the graph, we can conclude that:
1. Initially, for the higher value of DX, SRSD gives a higher value of error comparatively to other approximations schemes. but CD gives consistently lower value for the error.
2. After some value of DX, errors computing through SRSD and SLSD coming closer but the value of error for CD goes on increasing but still it is able to maintain an error lower than other schemes.
3. After many manipulations in the value of X, we will have completely different results. In that case, CD scheme error drastically gives rise whereas SLSD & SRSD able to give very much closer value to exact value.
4. Talking about FDS & BDS, both are very consistent in their error and closer to each other although they are providing higher value of error than the rest of schemes. They are having very lower accuracy but high precision we can expect.
5. When we compare CD & SRSD/SLSD, as the value of X changing nature of the CD curve will become more sensitive i.e. we can\'t expect greater accuracy. But if we consider the same with SRSD/SLSD initially they will have a higher value for error, as DX is decreasing it will start giving more accurate results and the curve will tend to move towards the exact result.
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 9 - Senstivity Analysis Assignment
Objective: To write the code which will take entire reactions of GRI mechanism 3.0 and take out the most sensitive top 10 reactions. The main parameters are as follows: Write code to list out the top 10 most sensitive reactions from a list of all reactions from the GRI mechanism. The sensitivity parameters should be with…
04 Jan 2021 05:51 PM IST
Auto ignition analysis of combustible mixture methane under different conditions using Cantera and Python
Objective: To study auto-ignition using Cantera. Following are the tasks to perform using Cantera: Plot the variation of Auto Ignition time of Methane with a constant temperature of 1250K and pressure varying from 1 to 5 atm. Plot the variation of Auto Ignition time…
06 Dec 2020 04:55 AM IST
Week 6 - Multivariate Newton Rhapson Solver
Objective: To solve a given set of Ordinary Differential equations using the Multi-Variate Newton Raphson Method. Given: The set of ODE's are given below: dy1dt=−0.04⋅y1+104⋅y2⋅y3 dy2dt=0.04⋅y1−104⋅y2⋅y3−3⋅107⋅y22 dy3dt=3⋅107⋅y22 The jacobian should be estimated numerically and not analytically.…
01 Nov 2020 03:50 AM IST
Week 5 - Literature review: ODE Stability
Objective: To review the literature about ODE and to write the python program to substantiate our results. Theory: …
20 Oct 2020 03:52 PM 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.