All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Derive the following 4th order approximations of the second-order derivative Aim: To derive the 4th order approximation for the second-order derivative of a given function using following 3 schemes. central difference skewed right difference skewed left difference schemes Working: MATLAB is used for coding to achieve the…
Dineshkumar Rajendran
updated on 30 Mar 2023
Derive the following 4th order approximations of the second-order derivative
Aim:
To derive the 4th order approximation for the second-order derivative of a given function using following 3 schemes.
Working:
Given function | exp(x)cos(x) |
Second-order Derivative of a function | -2*exp(x)*sin(x) |
Order of approximation | 4th order approximation |
At a Node | X = pi/3 (assumed for problem solving) |
1. Central difference
f(x) | dx f'(x) | dx^2 f''(x) | dx^3 f'''(x) | dx^4 f""(x) | dx^5 f""'(x) | |
a f(x-2dx) | a | -2a | 2a | -8a/6 | 16a/24 | -32a/120 |
b f(x-dx) | b | -b | b/2 | -b/6 | b/24 | -b/120 |
c f(x) | c | 0 | 0 | 0 | 0 | 0 |
d f(x+dx) | d | d | d/2 | d/6 | d/24 | d/120 |
e f(x+2dx) | e | 2e | 2e | 8e/6 | 16/24 | 32e/120 |
0 | 0 | 1 | 0 | 0 |
2. Skewed right-sided difference
f(x) | dx f'(x) | dx^2 f''(x) | dx^3 f'''(x) | dx^4 f""(x) | dx^5 f""'(x) | |
a f(x) | a | 0 | 0 | 0 | 0 | 0 |
b f(x+dx) | b | b | b/2 | b/6 | b/24 | b/120 |
c f(x+2dx) | c | 2c | 2c | 8c/6 | 16c/24 | 32c/120 |
d f(x+3dx) | d | 3d | 9d/2 | 27d/6 | 81d/24 | 243d/120 |
e f(x+4dx) | e | 4e | 16e | 64e/6 | 256/24 | 1024e/120 |
g f(x+5dx) | g | 5g | 25g/2 | 125g/6 | 625g/24 | 3125g/120 |
0 | 0 | 1 | 0 | 0 | 0 |
3. Skewed left-sided difference
f(x) | dx f'(x) | dx^2 f''(x) | dx^3 f'''(x) | dx^4 f""(x) | dx^5 f""'(x) | |
a f(x) | a | 0 | 0 | 0 | 0 | 0 |
b f(x-dx) | b | -b | b/2 | -b/6 | b/24 | -b/120 |
c f(x-2dx) | c | -2c | 2c | -8c/6 | 16c/24 | -32c/120 |
d f(x-3dx) | d | -3d | 9d/2 | -27d/6 | 81d/24 | -243d/120 |
e f(x-4dx) | e | -4e | 16e | -64e/6 | 256/24 | -1024e/120 |
g f(x-5dx) | g | -5g | 25g/2 | -125g/6 | 625g/24 | -3125g/120 |
0 | 0 | 1 | 0 | 0 | 0 |
Code
clear all
close all
clc
% to calculate a value of a function at a point x =pi/3
x= pi/3;
% coeffecient matrix derived for 4th order approximation
% a,b,c,d,e,f,g respectively
% calculated separately
% f''(x) = af(x-2dx)+bf(x-dx)+cf(x)+df(x+dx)+ef(x+2dx)/dx^2
central_scheme = [-0 + 1/(-12);1 + 1/(3);-3 + 1/(2);1 + 1/(3);-0 + 1/(-12)];
% f''(x) = af(x)+bf(x+dx)+cf(x+2dx)+df(x+3dx)+ef(x+4dx)+gf(x+5dx)/dx^2
right_skewed_scheme = [4 + 1/(-4);-13 + 1/(6);18 + 1/(-6);-13;5 + 1/(12);-1 + 1/(6)];
% f''(x) = af(x)+bf(x-dx)+cf(x-2dx)+df(x-3dx)+ef(x-4dx)+gf(x-5dx)/dx^2
left_skewed_scheme = [4 + 1/(-4);-13 + 1/(6);18 + 1/(-6);-13;5 + 1/(12);-1 + 1/(6)];
%given function =exp(x)*cos(x)
%second order derivative of this term
fun_x = exp(x)*cos(x);
second_order_derivative = -2*exp(x)*sin(x);
%discretization length dx
dx = linspace(pi/30,pi/30000,30);
for i = 1:length(dx)
%function at the node points with increment and decrement of dx
fun_xplusdx = exp(x+dx(i))*cos(x+dx(i));
fun_xplus2dx = exp(x+(2*dx(i)))*cos(x+(2*dx(i)));
fun_xplus3dx = exp(x+(3*dx(i)))*cos(x+(3*dx(i)));
fun_xplus4dx = exp(x+(4*dx(i)))*cos(x+(4*dx(i)));
fun_xplus5dx = exp(x+(5*dx(i)))*cos(x+(5*dx(i)));
fun_xminusdx = exp(x-dx(i))*cos(x-dx(i));
fun_xminus2dx = exp(x-(2*dx(i)))*cos(x-(2*dx(i)));
fun_xminus3dx = exp(x-(3*dx(i)))*cos(x-(3*dx(i)));
fun_xminus4dx = exp(x-(4*dx(i)))*cos(x-(4*dx(i)));
fun_xminus5dx = exp(x-(5*dx(i)))*cos(x-(5*dx(i)));
%cental difference scheme of 4 the order
C_1 = central_scheme(1)*fun_xminus2dx;
C_2 = central_scheme(2)*fun_xminusdx;
C_3 = central_scheme(3)*fun_x;
C_4 = central_scheme(4)*fun_xplusdx;
C_5 = central_scheme(5)*fun_xplus2dx;
central_fourth(i) = (C_1+C_2+C_3+C_4+C_5)/(dx(i)^2);
central_error(i) = abs(central_fourth(i)-second_order_derivative);
%for right skewed scheme of 4th order approximation
R_1 = right_skewed_scheme(1)*fun_x;
R_2 = right_skewed_scheme(2)*fun_xplusdx;
R_3 = right_skewed_scheme(3)*fun_xplus2dx;
R_4 = right_skewed_scheme(4)*fun_xplus3dx;
R_5 = right_skewed_scheme(5)*fun_xplus4dx;
R_6 = right_skewed_scheme(6)*fun_xplus5dx;
R_skewed_fourth(i) = (R_1+R_2+R_3+R_4+R_5+R_6)/(dx(i)^2);
Rskewed_error(i) = abs(R_skewed_fourth(i)-second_order_derivative);
%for left skewed scheme of 4th order approximation
L_1 = left_skewed_scheme(1)*fun_x;
L_2 = left_skewed_scheme(2)*fun_xminusdx;
L_3 = left_skewed_scheme(3)*fun_xminus2dx;
L_4 = left_skewed_scheme(4)*fun_xminus3dx;
L_5 = left_skewed_scheme(5)*fun_xminus4dx;
L_6 = left_skewed_scheme(6)*fun_xminus5dx;
L_skewed_fourth(i) = (L_1+L_2+L_3+L_4+L_5+L_6)/(dx(i)^2);
Lskewed_error(i) = abs(L_skewed_fourth(i)-second_order_derivative);
end
loglog(dx,central_error,'linewidth',3,'color','g')
hold on
loglog(dx,Rskewed_error,'linewidth',3,'color','r')
hold on
loglog(dx,Lskewed_error,'linewidth',3,'color','y')
legend('central scheme error','right skewed scheme error','left skewed scheme error')
xlabel('range of dx')
ylabel('Truncation error')
title('Comparision of central, right skewed and left skewed 4th order approximation for second order derivative')
Results
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 7 - Simulation of a 1D Supersonic nozzle flow simulation using Macormack Method
Objective : To simulate the isentropic flow through a quasi 1D subsonic-supersonic nozzle by deriving both conservative and non conservative forms of governing equation and solve them by using Macormack Method in matlab. Problem statement : Need to determine the steady-state temperature distribution for the flow-field…
13 Apr 2023 04:54 AM IST
Week 5.1 - Mid term project - Solving the steady and unsteady 2D heat conduction problem
Aim 1. Steady state analysis & Transient State Analysis Solve the 2D heat conduction equation by using the point iterative techniques . The Boundary conditions for the problem are as follows; Top Boundary = 600 K Bottom Boundary = 900 K Left Boundary = 400 K Right Boundary = 800 K You will implement the following methods…
12 Apr 2023 07:36 AM IST
Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
Derive the following 4th order approximations of the second-order derivative Aim: To derive the 4th order approximation for the second-order derivative of a given function using following 3 schemes. central difference skewed right difference skewed left difference schemes Working: MATLAB is used for coding to achieve the…
30 Mar 2023 09:43 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.