All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Deraviation of 4th order approximations of the second-order derivative using various schemes:- The given function is exp(x)⋅cos(x) The second derivative is :- −2⋅exp(x)⋅sin(x) 1. Central Difference Scheme:- As given, no. of Nodes (N) required for 4rth order approximation (P = 4) of 2nd order deravative (Q…
Vipul Anand
updated on 21 Mar 2021
Deraviation of 4th order approximations of the second-order derivative using various schemes:-
The given function is
exp(x)⋅cos(x)
The second derivative is :-
−2⋅exp(x)⋅sin(x)
1. Central Difference Scheme:-
As given, no. of Nodes (N) required for 4rth order approximation (P = 4) of 2nd order deravative (Q = 2) is :-
P = N - Q + 1
so, N = P + Q -1
so, N = 4 + 2 -1 = 5
For the central difference with 5 nodes,
the 4rth order approximation of 2nd order differential using central difference scheme with unknown coefficients(a,b,c,d,e) can be expressed as below,
∂2f∂x2≈f''(x)+Δx4f6(x)⋅(constants)=af(x−2dx)+bf(x−dx)+cf(x)+df(x+dx)+ef(x+2dx)Δx2
Using Taylor's Table:-
f(x) | (Δx)f'(x) | (Δx)2f''(x) | (Δx)3f'''(x) | (Δx)4fiv(x) | (Δx)5fv(x) | (Δx)6fvi(x) | |
af(x−2dx) | a | −2a | 2a | −4a3 | 2a3 | −4a15 | 4a45 |
bf(x−dx) | b | −b | b2 | −b6 | b24 | −b120 | b720 |
cf(x) | c | 0 | 0 | 0 | 0 | 0 | 0 |
df(x+dx) | d | d | d2 | d6 | d24 | d120 | d720 |
ef(x+2dx) | e | 2e | 2e | 4e3 | 2e3 | 4e15 | 4e45 |
0 | 0 | 1 | 0 | 0 | ? | ? |
Solving for unknown coefficients,
a+b+c+d+e=0
−2a−b+d+2e=0
2a+b2+d2+2e=1
−4a3−b6+d6+4e3=0
2a3+b24+d24+2e3=0
Using linsolve to solve the above linear equations:-
Thus the value of a is -0.0833, b is 1.3333, c is -2.5, d is 1.3333, e is -0.833
2. Skewed Right-Sided Difference:-
The 4rth order approximation of 2nd order differential using Skewed Right-Sided difference scheme with unknown coefficients(a,b,c,d,e,g) can be expressed as below,
∂2f∂x2≈f''(x)+Δx4f6(x)⋅(constants)=af(dx)+bf(x+dx)+cf(x+2dx)+df(x+3dx)+ef(x+4dx)+gf(x+5dx)Δx2
Proof of order of accuracy according to the given rule (The order of accuracy P = Number of nodes in the stencil N - order of derivative Q )
So, As per the rule:- Order of accuracy P = N - Q
N (Number of Nodes or Points) = 6 [We have taken no. of points to be 6]
Q (Order of derivative) = 2 [We are solving for 2nd order of derivative]
So, P (the order of accuracy) should be 6 - 2 = 4.
Also, the order of accuracy we are solving for is 4, so as per the statement, the order of accuracy has been proved.
Using Taylor's Table:-
f(x) | (Δx)f'(x) | (Δx)2f''(x) | (Δx)3f'''(x) | (Δx)4fiv(x) | (Δx)5fv(x) | |
af(x) | a | 0 | 0 | 0 | 0 | 0 |
bf(x+dx) | b | b | b2 | b6 | b24 | b120 |
cf(x+2dx) | c | 2c | 4c2 | 8c6 | 16c24 | 32c120 |
df(x+3dx) | d | 3d | 9d2 | 27d6 | 81d24 | 243d120 |
ef(x+4dx) | e | 4e | 16e2 | 64e6 | 256e24 | 1024e120 |
gf(x+5dx) | g | 5g | 25g2 | 125g6 | 625g24 | 3125g120 |
0 | 0 | 1 | 0 | 0 | 0 |
Solving for unknown coefficients:-
a+b+c+d+e+g=0
b+2c+3d+4e+5g=0
b2+4c2+9d2+16e2+25g2=1
b6+8c6+27d6+64e6+125g6=0
b24+16c24+81d24+256e24+625g24=0
b120+32c120+243d120+1024e120+3125g120=0
Solving above linear Equations we get :-
The coefficients thus calculated are :-
a = 3.75, b = -12.8333, c = 17.8333, d = -13, e= 5.0833, g = -0.8333
3. Skewed Left-Sided Difference:-
The 4rth order approximation of 2nd order differential using Skewed Left-Sided difference scheme with unknown coefficients(a,b,c,d,e,g) can be expressed as below,
∂2f∂x2≈f''(x)+Δx4f6(x)⋅(constants)=af(dx)+bf(x−dx)+cf(x−2dx)+df(x−3dx)+ef(x−4dx)+gf(x−5dx)Δx2
Proof of order of accuracy according to the given rule (The order of accuracy P = Number of nodes in the stencil N - order of derivative Q )
So, As per the rule:- Order of accuracy P = N - Q
N (Number of Nodes or Points) = 6 [We have taken no. of points to be 6]
Q (Order of derivative) = 2 [We are solving for 2nd order of derivative]
So, P (the order of accuracy) should be 6 - 2 = 4.
Also, the order of accuracy we are solving for is 4, so as per the statement, the order of accuracy has been proved.
Using Taylor's Table:-
f(x) | (Δx)f'(x) | (Δx)2f''(x) | (Δx)3f'''(x) | (Δx)4fiv(x) | (Δx)5fv(x) | |
af(x) | a | 0 | 0 | 0 | 0 | 0 |
bf(x−dx) | b | −b | b2 | −b6 | b24 | −b120 |
cf(x−2dx) | c | −2c | 4c2 | −8c6 | 16c24 | −32c120 |
df(x−3dx) | d | −3d | 9d2 | −27d6 | 81d24 | −243d120 |
ef(x−4dx) | e | −4e | 16e2 | −64e6 | 256e24 | −1024e120 |
gf(x−5dx) | g | −5g | 25g2 | −125g6 | 625g24 | −3125g120 |
0 | 0 | 1 | 0 | 0 | 0 |
Solving for the unknown coefficients we get:-
a+b+c+d+e+g=0
−b−2c−3d−4e−5g=0
b2+4c2+9d2+16e2+25g2=1
−b6−8c6−27d6−64e6−125g6=0
b24+16c24+81d24+256e24+625g24=0
−b120−32c120−243d120−1024e120−3125g120=0
The coefficients thus calculated are :-
a = 3.75, b = -12.8333, c = 17.8333, d = -13, e= 5.0833, g = -0.8333
The solution using matlab code is described below:-
A few Helper functions are defined:-
Function absError
function outputArg1 = absError(inputArg1,inputArg2)
%Calculates the absolute error
%
outputArg1 = log(abs(inputArg1-inputArg2));
end
Function analyticDerivative
function [outputArg1] = analyticDerivitive(x)
% This function calcultates the second derivative of function
% exp(x)*cos(x)
% Parameter x represents the point on which derivative is to be calculated.
outputArg1 = -2*exp(x)*sin(x);
end
Function centralDifference
function outputArg1 = centralDifference(x, dx, fun, X, analytic_result)
%This function calcultates the second deravative by central difference
%scheme. The parameters :-
% x = point at which derivative is to be calculated.
% dx = step size or grid size
% fun = given function
% X = coefficients for central scheme is calculated
% analytic_result = the value of derivative calculated by analytical method
value = (X(1)*fun(x-2*dx) + X(2)*fun(x-dx) + X(3)*fun(x) + X(4)*fun(x+dx) + X(5)*fun(x+2*dx))/(dx^2);
outputArg1 = absError(value, analytic_result);
end
Function leftDifference
function outputArg1 = leftDifference(x,dx, fun, X, analytic_result)
%This function calcultates the second deravative by left difference
%scheme. The parameters :-
% x = point at which derivative is to be calculated.
% dx = step size or grid size
% fun = given function
% X = coefficients for left sided scheme is calculated
% analytic_result = the value of derivative calculated by analytical method
value = (X(1)*fun(x)+X(2)*fun(x-dx)+ X(3)*fun(x-2*dx) + X(4)*fun(x-3*dx) + X(5)*fun(x-4*dx) + X(6)*fun(x-5*dx))/(dx^2);
outputArg1 = absError(value,analytic_result);
end
Function rightDifference
function outputArg1 = rightDifference(x,dx, fun, X, analytic_result)
%This function calcultates the second deravative by right difference
%scheme. The parameters :-
% x = point at which derivative is to be calculated.
% dx = step size or grid size
% fun = given function
% X = coefficients for right sided scheme is calculated
% analytic_result = the value of derivative calculated by analytical method
value = (X(1)*fun(x)+X(2)*fun(x+dx)+ X(3)*fun(x+2*dx) + X(4)*fun(x+3*dx) + X(5)*fun(x+4*dx) + X(6)*fun(x+5*dx))/(dx^2);
outputArg1 = absError(value, analytic_result);
end
Function givenFunction
function outputArg1 = givenFunction(x)
%Calculate the value of given function at point x.
% Outputs the value of given function exp(x)*cos(x) at given point.
% Parameter x represents the point on which value is to be calculated.
outputArg1 = exp(x)*cos(x);
end
The driver Script
close all
clear all
clc
% Point on which derivative is to be calculated
x = pi/4;
% The varying Grid Size
dx = linspace(pi/10,pi/250,1000);
% The derivative calculated analyticaly
analytic_result = analyticDerivitive(x);
% Coefficients for central, left sided, right sided difference are calculated based on the matrix
% formed
% Central Difference Scheme
A_central = [1,1,1,1,1;-2,-1,0,1,2;2,1/2,0,1/2,2;-4/3,-1/6,0,1/6,4/3;2/3,1/24,0,1/24,2/3];
B_central = [0;0;1;0;0];
X_central = linsolve(A_central,B_central);
% Left Sided Difference Scheme
A_left = [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_left = [0;0;1;0;0;0];
X_left = linsolve(A_left,B_left);
% Right Sided Difference Scheme
A_right = [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_right = [0;0;1;0;0;0];
X_right = linsolve(A_right,B_right);
% The errors matrix is initialized
errors = zeros(length(dx),3);
for i = 1:length(dx)
errors(i,1) = centralDifference(x,dx(i), @givenFunction, X_central, analytic_result);
errors(i,2) = leftDifference(x,dx(i), @givenFunction, X_left, analytic_result);
errors(i,3) = rightDifference(x,dx(i), @givenFunction, X_right, analytic_result);
end
figure(1)
plot(dx,errors(:,1), 'linewidth', 1.5);
title("Comparing different Schemes with Grid Size")
hold on
plot(dx,errors(:,2), 'linewidth', 1.5);
hold on
plot(dx, errors(:,3), 'linewidth', 1.5);
hold on
xlabel("Grid Size")
ylabel("Log(Error)")
legend('Central Difference Scheme', 'Left Difference Scheme', 'Right Difference Scheme')
The Error plots are below:-
Conclusions:-
The Central Difference method having less error even at higher grid sizes depicts its reliablity in accuracy as compared to other two schemes. As, it takes care of information from left as well as right side of the point of interest. Since there is lack of information at the boundary of domain from atleast one side of point of interest, so central difference scheme wont work.
So At boundary nodes either left or right sided skewed schemes are preferred.
As can be seen from the plot above skewed schemes have relatively same perfomance at smaller grid size.
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...
Senstivity Analysis - GRI Mechanism
Introduction: Sensitivity analysis given an overview of magnitude of variation of an independent variable over dependent variable. It is the study that helps in investigation of factors that has the potential to alter the given outcome. Since our study is focussed on the chemical reactions, the reactants and their initial…
04 Jul 2022 02:31 PM IST
FULL HYDRO case set up (PFI)
Objective:- Simulate PFI - engine in Converge CFD Geometry The prepared geometry from the previous section has been used in the present simulation. Simulation Type of Simulation Crank angle-based IC engine simulation The given parameters were, RPM of 3000 Connecting rod of length 0.18m Stroke of length 0.09m…
04 Jul 2022 02:25 PM IST
Simulation of Flat Plate Heat Sink
Detailed Objectives and Motivation Flat plate heats sinks are most common cooling solution for low to medium heat dissipating electronic equipment. Its ease in manufacturing attracts diverse range of material selection with required thermal properties. Selection of material is not the only part and parcel in manufacturing…
04 Jul 2022 02:24 PM IST
Simulation of Flow over a Cylinder and Explaining the phenomenon of Karman Vortex Street
Project Report - Flow over a Cylinder Introduction Flow past object, has been a topic of interest since long time. The phenomenon is very common in engineering designs. The complex nature of physics and behaviour of transport phenomenon around the object is still being actively studied. The nature of flow changes at critical…
04 Jul 2022 01:49 PM 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.