All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective > Derive the following 4th order approximations of the second-order derivative. Central difference Skewed right-sided difference Skewed left-sided difference > To prove that the skewed schemes are fourth-order accurate. > Write a program in Matlab to evaluate the second-order derivative of the…
Jeffry Raakesh
updated on 23 Aug 2021
Objective
> Derive the following 4th order approximations of the second-order derivative.
> To prove that the skewed schemes are fourth-order accurate.
> Write a 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 derived.
> Generate a plot that compares the absolute error between the above-mentioned schemes.
> Explain why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot?
4th Order approximations of the second-order derivative
Central difference
The number of nodes in the stencil can be calculated by the formula
N = P + Q - 1
Where,
N - Number of nodes
P - Order of approximations
Q - Order of derivative
Note: 1 is subtracted to derive the central scheme
To derive 4th order approximation of the second-order derivative, the number of nodes required for a central scheme is
N = 4 + 2 -1
N = 5
The hypothesis equation for central scheme with 5 nodes will be
∂2x∂y2=af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2)∂2x∂y2=af(i−2)+bf(i−1)+cf(i)+df(i+1)+ef(i+2)
Expanding all the terms in taylor series we get
af(i-2)=af(i)-a2Δx1!f′(i)+a(2Δx)22!f′′(i)-a(2Δx)33!f′′′(i)+a(2Δx)44!f′′′′(i)-a(2Δx)55!f′′′′′(i)+a(2Δx)66!f′′′′′′(i)+...
bf(i-1)=bf(i)-bΔx1!f′(i)+b(Δx)22!f′′(i)-b(Δx)33!f′′′(i)+b(Δx)44!f′′′′(i)-b(Δx)55!f′′′′′(i)+b(Δx)66!f′′′′′′(i)-...
cf(i)=cf(i)
df(i+1)=df(i)+dΔx1!f′(i)+d(Δx)22!f′′(i)+d(Δx)33!f′′′(i)+d(Δx)44!f′′′′(i)+d(Δx)55!f′′′′′(i)+d(Δx)66!f′′′′′′(i)+...
ef(i+2)=ef(i)+e2Δx1!f′(i)+e(2Δx)22!f′′(i)+e(2Δx)33!f′′′(i)+e(2Δx)44!f′′′′(i)+e(2Δx)55!f′′′′′(i)+e(2Δx)66!f′′′′′′(i)+...
Taylor table representation
Terms→ | f(i) | Δxf′(i) | Δx2f′′(i) | Δx3f′′′(i) | Δx4f′′′′(i) | Δx5f′′′′′(i) |
af(i-2) | a | -2a | 4a2 | -8a6 | 16a24 | -32a120 |
bf(i-1) | b | -b | b2 | -b6 | b24 | -b120 |
cf(i) | c | 0 | 0 | 0 | 0 | 0 |
df(i+1) | d | d | d2 | d6 | d24 | d120 |
ef(i+2) | e | 2e | 4e2 | 8e6 | 16e24 | 32e120 |
Sum→ | 0 | 0 | 1 | 0 | 0 | ? |
Matrix representation
[11111-2-1012421201242-86-1601686162412401241624-32120-11200112032120][abcde]=[00100]
MATLAB is used to solve the above matrix equation
The solved variable "X" has the values of a,b,c,d,e which are substituted in the hypothesis equation
∂2x∂y2=-0.833f(i-2)+1.3333f(i-1)-2.5f(i)+1.3333f(i+1)-0.0833f(i+2)Δx2
Skewed Right-side difference
The number of nodes in the stencil can be calculated by the formula
N = P + Q
Where,
N - Number of nodes
P - Order of approximations
Q - Order of derivative
To derive 4th order approximation of the second-order derivative, the number of nodes required for a skewed right side scheme is
N = 4 + 2
N = 6
The hypothesis equation for skewed right side scheme with 6 nodes will be
∂2x∂y2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)
Taylor table representation
Terms→ | f(i) | Δxf′(i) | Δx2f′′(i) | Δx3f′′′(i) | Δx4f′′′′(i) | Δx5f′′′′′(i) | Δx6f′′′′′(i) |
af(i) | a | 0 | 0 | 0 | 0 | 0 | 0 |
bf(i+1) | b | b | b2 | b6 | b24 | b120 | b720 |
cf(i+2) | c | 2c | 4c2 | 8c6 | 16c24 | 32c120 | 64c720 |
df(i+3) | d | 3d | 9d2 | 27d6 | 81d24 | 243d120 | 729d720 |
ef(i+4) | e | 4e | 16e2 | 64e6 | 256e24 | 1024e120 | 4096e720 |
gf(i+5) | g | 5g | 25g2 | 125g6 | 625g24 | 3125g120 | 15625g720 |
Sum→ | 0 | 0 | 1 | 0 | 0 | 0 | ? |
Matrix representation
[11111101234501242921622520168627664612560124162481242562462524011203212024312010241203125120][abcdeg]=[001000]
MATLAB is used to solve the above matrix equation
The solved variable "X" has the values of a,b,c,d,e which are substituted in the hypothesis equation
∂2x∂y2=3.75f(i)-12.8333f(i+1)+17.8333f(i+2)-13f(i+3)+5f(i+4)-0.8333f(i+5)Δx2
Skewed Left-side difference
The number of nodes in the stencil can be calculated by the formula
N = P + Q
Where,
N - Number of nodes
P - Order of approximations
Q - Order of derivative
To derive 4th order approximation of the second-order derivative, the number of nodes required for a skewed right side scheme is
N = 4 + 2
N = 6
The hypothesis equation for skewed right side scheme with 6 nodes will be
∂2x∂y2=af(i)+bf(i-1)+cf(i-2)+df(i-3)+ef(i-4)+gf(i-5)
Taylor table representation
Terms→ | f(i) | Δxf′(i) | Δx2f′′(i) | Δx3f′′′(i) | Δx4f′′′′(i) | Δx5f′′′′′(i) | Δx6f′′′′′(i) |
af(i) | a | 0 | 0 | 0 | 0 | 0 | 0 |
bf(i-1) | b | -b | b2 | -b6 | b24 | -b120 | b720 |
cf(i-2) | c | -2c | 4c2 | -8c6 | 16c24 | -32c120 | 64c720 |
df(i-3) | d | -3d | 9d2 | -27d6 | 81d24 | -243d120 | 729d720 |
ef(i-4) | e | -4e | 16e2 | -64e6 | 256e24 | -1024e120 | 4096e720 |
gf(i-5) | g | -5g | 25g2 | -125g6 | 625g24 | -3125g120 | 15625g720 |
Sum→ | 0 | 0 | 1 | 0 | 0 | 0 | ? |
Matrix representation
[1111110-1-2-3-4-501242921622520-16-86-276-646-125601241624812425624625240-1120-32120-243120-1024120-3125120][abcdeg]=[001000]
MATLAB is used to solve the above matrix equation
The solved variable "X" has the values of a,b,c,d,e which are substituted in the hypothesis equation
∂2x∂y2=3.75f(i)-12.8333f(i+1)+17.8333f(i+2)-13f(i+3)+5f(i+4)-0.8333f(i+5)Δx2
Matlab program to evaluate the second-order derivative of the analytical function exp(x)*cos(x) and to compare it with the 3 numerical approximations derived.
clear all
close all
clc
% Inputs
x = pi/3;
dx = linspace(pi/700,pi/4,100);
% Analytical_Function
% f(x) = exp(x)*cos(x)
% f''(x) = -2*exp(x)*sin(x)
a_d = -2*exp(x)*sin(x);
% Creating anonymous function
f =@(x) exp(x)*cos(x);
% Deriving the numerical schemes
% Central difference
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];
Xc= linsolve(A,B);
% Skewed Right side difference
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];
Xr= linsolve(A,B);
% Skewed Left side difference
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];
Xl= linsolve(A,B);
% Numerical derivative
for i = 1:length(dx)
% Central Difference
Nd_Cd(i) = (Xc(1)*f(x-2*dx(i))+Xc(2)*f(x-1*dx(i))+Xc(3)*f(x)+Xc(4)*f(x+1*dx(i))+Xc(5)*f(x+2*dx(i)))/(dx(i)^2);
% Skewed right side difference
Nd_Sr(i) = (Xr(1)*f(x)+Xr(2)*f(x+1*dx(i))+Xr(3)*f(x+2*dx(i))+Xr(4)*f(x+3*dx(i))+Xr(5)*f(x+4*dx(i))+Xr(6)*f(x+5*dx(i)))/(dx(i)^2);
% Skewed left side difference
Nd_Sl(i) = (Xl(1)*f(x)+Xl(2)*f(x-1*dx(i))+Xl(3)*f(x-2*dx(i))+Xl(4)*f(x-3*dx(i))+Xl(5)*f(x-4*dx(i))+Xl(6)*f(x-5*dx(i)))/(dx(i)^2);
% Absolute error value calculation
% Error values of Central difference
E_Cd(i) = abs(Nd_Cd(i) - a_d);
% Error values of skewed right side difference
E_Sr(i) = abs(Nd_Sr(i) - a_d);
% Error values of skewed left side difference
E_Sl(i) = abs(Nd_Sl(i) - a_d);
end
% Plot
figure(1)
loglog(dx,E_Cd,'b','LineWidth',1.5)
hold on
loglog(dx,E_Sr,'k','LineWidth',1.5)
loglog(dx,E_Sl,'r','LineWidth',1.5)
title('Comparison of differencing schemes')
xlabel('Range of dx')
ylabel('Error values of different schemes')
legend('Central difference','Skewed right side difference','Skewed left side difference')
Program explanation
> At first, the inputs x and dx are given.
> Then the second derivative of the analytical function is stored to a variable which can be used for error calculation later in the program.
> An anonymous function for the function exp(x)⋅cos(x) is created.
> The numerical schemes "Central differencing, Skewed right side differencing, Skewed left side differencing" are derived using the pre-work done before programming.
> A loop for the length of dx is generated in which, the function is numerically solved using the 3 derived schemes.
> The anonymous function is called to solve the numerical derivatives which are then stored in their respective arrays.
> The absolute error values of the three schemes are also calculated in the same loop using the value of the analytical derivative.
> The log log plot is made between the error values of these three schemes and the range of dx where the solution is stable.
Result
> The range of dx (pi/4 - pi/700) is where the solution is stable comparatively.
> From the above plot, it can be seen that the central difference scheme is more stable and have the lowest error.
> The instability in the skewed left side difference scheme might be formed due to the truncation error or by the value of dx.
> Hence, the errors of the three schemes for the function exp(x)⋅cos(x) are compared.
Skewed schemes
> Although skewed schemes are less accurate in the above case they hold the advantage to calculate the approximation in any order.
> If boundary conditions are given then, skewed schemes come in handy compared to the CD scheme.
> For convection and diffusion equations, the CD scheme produces unstable solutions.
> Skewed schemes can be used for backwards differencing(left side) as well as forward differencing(right side) whereas, the central scheme can only be used for an internal solution.
> Skewed schemes require information from only one direction but, CD schemes require information from both sides.
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...
Solving 1D Linear convection equation using MATLAB
Objective > Write a Matlab code to simulate a One-dimensional Linear Convection equation. Conditions > The initial velocity profile is a step function. It is equal to 2m/s between x= 0.1 and 0.3 and 1m/s everywhere else > length is L = 1m > First-order forward differencing for the time derivative…
26 Aug 2021 12:45 PM IST
Deriving 4th order approximation of a 2nd order derivative by differencing schemes and evaluating them using MATLAB
Objective > Derive the following 4th order approximations of the second-order derivative. Central difference Skewed right-sided difference Skewed left-sided difference > To prove that the skewed schemes are fourth-order accurate. > Write a program in Matlab to evaluate the second-order derivative of the…
23 Aug 2021 07:21 AM IST
Curve fitting using Matlab
Objective > Write code to fit a linear and cubic polynomial for the given data. > To measure the fitness characteristics for both the curves. > Write code to fit a curve using splitwise method. > To explain best fit, perfect fit, and improvements for cuibc fit. Solution The code to fit a linear…
28 Mar 2021 04:00 PM IST
Breaking Ice with Air cushion Vehicle - Find minimum pressure with Newton-Raphson method in Python
Objective > To find out the value of pressure for h = 0.6 ft by the below given equation using Newton-Raphson method. p3(-β2)+(0.4hβ2-σh2r2)p2+(σ2h43r4)p-(σh23r2)3=0 p = Cushion pressure β = Width of the ice wedge …
28 Mar 2021 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.