All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Problem Statement: - For the Function f(x)=ex⋅cos(x)f(x)=ex⋅cos(x) derive the 4th Order Accurate Approximation of 2nd Order Derivative for the given function using Taylor Table Method for the following difference Methods: - 1. Central Difference 2. Skewed right-sided difference 3. Skewed left-sided difference Write A MATLAB…
Aditya Aanand
updated on 09 Sep 2022
Problem Statement: -
For the Function f(x)=ex⋅cos(x)f(x)=ex⋅cos(x) derive the 4th Order Accurate Approximation of 2nd Order Derivative for the given function using Taylor Table Method for the following difference Methods: -
1. Central Difference 2. Skewed right-sided difference 3. Skewed left-sided difference
Write A MATLAB Code to Solve the function using the derived 4th Order Approximate 2nd Order Derivative and compare it with the 2nd Order Derivative of Analytical Solution
Solution: -
1. AIM: -
A. To Derive 4th Order Approximation for 2nd Order Derivative using: -
a. Central Difference Method
b. Skewed Right-Side Difference Method
c. Skewed Left-Side Difference Method
B. Prove each Method to Be 4th Order Accurate
C. Write a MATLAB Code to Solve a function using all 3 Methods
D. Comment on the usefulness of Skewed Methods
2. Given: -
A. P = N - Q + ({1 for CDM} or {0 for Skewed Method})
Here,
P - Order of Accuracy of Approximation
N - Number of Nodes in Numerical Stensil
Q - Order of Derivative
CDM - Central Difference Method
B. Function→f(x)=ex⋅cos(x) Function→f(x)=ex⋅cos(x)
3. Assumed: -
A. Differentiation Point(x)=π3Differentiation Point(x)=π3
4. Analytical Derivative Formula: -
second Derivative→∂2f(x)∂x2=-2ex⋅sin(x)
5. Formulas & Derivation of The Approximation Methods: -
A. Central Difference Method: -
For calculating the 4th Order Approximation and 2nd Order Derivative
(P=4) = N - (Q=2) + 1
=> Number of Nodes in Numerical Stensil(N) = 5
So,
Numerical Stensil for Central Difference Method
Let, (dx)2∂2f(x)∂x2=af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2)
Using Taylor Table Method For Central Difference Method
Numerical Stensil ↓ | f(i) | (dx)∂f(i)∂x | (dx)2∂2f(i)∂x2 | (dx)3∂3f(i)∂x3 | (dx)4∂4f(i)∂x4 |
af(i-2) | a | -2a | 4a2 | -8a6 | 16a24 |
bf(i-1) | b | -b | b2 | -b6 | b24 |
cf(i) | c | 0 | 0 | 0 | 0 |
df(i+1) | d | d | d2 | d6 | d24 |
ef(i+2) | e | 2e | 4e2 | 8e6 | 16e24 |
Sum=(dx)2∂2f(x)∂x2 | 0 | 0 | 1 | 0 | 0 |
On Solving,
a=e=-112
b=d=43
c=52
Hence,
(dx)2∂2f(x)∂x2=-112f(i-2)+43f(i-1)-52f(i)+43f(i+1)-112f(i+2)
4th Order Approximation for 2nd Order Derivative of Central Difference Method
∂2f(x)∂x2=-112f(i-2)+43f(i-1)-52f(i)+43f(i+1)-112f(i+2)(dx)2 |
B. Skewed Right-Side Difference Method: -
For Calculating 4th Order Approximation and 2nd Order Derivative
(P=4) = N - (Q=2) + 0
=> Number of Nodes in Numerical Stensil(N) = 6
So,
Numerical Stensil for Skewed Right-Side Difference Method
Let, (dx)2∂2f(x)∂x2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+ff(i+5)
Numerical Stensil ↓ | f(i) | (dx)∂f(i)∂x | (dx)2∂2f(i)∂x2 | (dx)3∂3f(i)∂x3 | (dx)4∂4f(i)∂x4 | (dx)5∂5f(i)∂x5 |
af(i) | a | 0 | 0 | 0 | 0 | 0 |
bf(i+1) | b | b | b2 | b6 | b24 | b120 |
cf(i+2) | c | 2c | 4c2 | 8c6 | 16c24 | 32c120 |
df(i+3) | d | 3d | 9d2 | 27d6 | 81d24 | 729d120 |
ef(i+4) | e | 4e | 16e2 | 64e6 | 256e24 | 1024e120 |
ff(i+5) | f | 5f | 25f2 | 125f6 | 625f24 | 3125f120 |
Sum=(dx)2∂2f(x)∂x2 | 0 | 0 | 1 | 0 | 0 | 0 |
On Solving,
a=154
b=-776
c=1076
d=-13
e=671132
f=-56
Hence,
(dx)2∂2f(x)∂x2=154f(i)-776f(i+1)+1076f(i+2)-13f(i+3)+671132f(i+4)-56f(i+5)
4th Order Approximation for 2nd Order Derivative of Skewed Right-Side Difference Method
∂2f(x)∂x2=154f(i)-776f(i+1)+1076f(i+2)-13f(i+3)+671132f(i+4)-56f(i+5)(dx)2 |
C. Skewed Left-Side Difference Method: -
For Calculating 4th Order Approximation and 2nd Order Derivative
(P=4) = N - (Q=2) + 0
=> Number of Nodes in Numerical Stensil(N) = 6
So,
Numerical Stensil for Skewed Right-Side Difference Method
Let, (dx)2∂2f(x)∂x2=af(i-5)+bf(i-4)+cf(i-3)+df(i-2)+ef(i-1)+ff(i)
Numerical Stensil ↓ | f(i) | (dx)∂f(i)∂x | (dx)2∂2f(i)∂x2 | (dx)3∂3f(i)∂x3 | (dx)4∂4f(i)∂x4 | (dx)5∂5f(i)∂x5 |
af(i-5) | a | -5a | 25a2 | -125a6 | 625a24 | -3125a120 |
bf(i-4) | b | -4b | 16b2 | -64b6 | 256b24 | -1024b120 |
cf(i-3) | c | -3c | 9c2 | -27c6 | 81c24 | -729c120 |
df(i-2) | d | -2d | 4d2 | -8d6 | 16d24 | -32d120 |
ef(i-1) | e | -e | e2 | -e6 | e24 | -e120 |
ff(i) | f | 0 | 0 | 0 | 0 | 0 |
Sum=(dx)2∂2f(x)∂x2 | 0 | 0 | 1 | 0 | 0 | 0 |
On Solving,
a=-56
b=671132
c=-13
d=1076
e=-776
f=154
Hence,
(dx)2∂2f(x)∂x2=-56f(i-5)+671132f(i-4)-13f(i-3)+1076f(i-2)-776f(i-1)+154f(i)
4th Order Approximation for 2nd Order Derivative of Skewed Right-Side Difference Method
∂2f(x)∂x2=-56f(i-5)+671132f(i-4)-13f(i-3)+1076f(i-2)-776f(i-1)+154f(i)(dx)2 |
6. Proving That the Above Derived Formulas are 4th Order Accurate: -
A. Central Difference Method: -
As form proof the Coefficients of f(x),(dx)∂f(x)∂x,(dx)3∂3f(x)∂3xand(dx)4∂4f(x)∂x4 are equated to Zero(0) now for the Given Value of a, b, c, d, and e
Checking the Coefficient of(dx)5∂5f(x)∂x5
Coefficient of (dx)5∂5f(x)∂x5=-32a120-b120+0+d120+32e120
For,a=e=-112andb=d=43
Coefficient of (dx)5∂5f(x)∂x5=0
Hence,
....+(coefficient of fIV(x))(dx)6∂6f(x)∂x6+(1)(dx)2∂2f(x)∂x2=-112f(i-2)+43f(i-1)-52f(i)+43f(i+1)-112f(i+2)
Dividing Both-sides from(dx)2
⇒....+(coefficient of fIV(x))(dx)4∂6f(x)∂x6+∂2f(x)∂x2=-112f(i-2)+43f(i-1)-52f(i)+43f(i+1)-112f(i+2)(dx)2
Ignoring All multiples of dx4 (=> The Order of Accuracy is 4th Order)
∂2f(x)∂x2=-112f(i-2)+43f(i-1)-52f(i)+43f(i+1)-112f(i+2)(dx)2
B. Skewed Right-Side Difference Method: -
As form proof the Coefficients of f(x),(dx)∂f(x)∂x,(dx)3∂3f(x)∂3x,(dx)4∂4f(x)∂x4and(dx)5∂5f(x)∂x5 are equated to Zero(0)
Hence,
....+(coefficient of fIV(x))(dx)6∂6f(x)∂x6+(1)(dx)2∂2f(x)∂x2=154f(i)-776f(i+1)+1076f(i+2)-13f(i+3)+671132f(i+4)-56f(i+5)
Dividing Both-sides from(dx)2
⇒....+(coefficient of fIV(x))(dx)4∂6f(x)∂x6+∂2f(x)∂x2=154f(i)-776f(i+1)+1076f(i+2)-13f(i+3)+671132f(i+4)-56f(i+5)(dx)2
Ignoring All multiples of dx4 (=> The Order of Accuracy is 4th Order)
∂2f(x)∂x2=154f(i)-776f(i+1)+1076f(i+2)-13f(i+3)+671132f(i+4)-56f(i+5)(dx)2
C. Skewed Left-Side Difference Method: -
As form proof the Coefficients of f(x),(dx)∂f(x)∂x,(dx)3∂3f(x)∂3x,(dx)4∂4f(x)∂x4and(dx)5∂5f(x)∂x5 are equated to Zero(0)
Hence,
....+(coefficient of fIV(x))(dx)6∂6f(x)∂x6+(1)(dx)2∂2f(x)∂x2=-56f(i-5)+671132f(i-4)-13f(i-3)+1076f(i-2)-776f(i-1)+154f(i)
Dividing Both-sides from(dx)2
⇒....+(coefficient of fIV(x))(dx)4∂6f(x)∂x6+∂2f(x)∂x2=-56f(i-5)+671132f(i-4)-13f(i-3)+1076f(i-2)-776f(i-1)+154f(i)(dx)2
Ignoring All multiples of dx4 (=> The Order of Accuracy is 4th Order)
∂2f(x)∂x2=-56f(i-5)+671132f(i-4)-13f(i-3)+1076f(i-2)-776f(i-1)+154f(i)(dx)2
7. Explanation of Code: -
A. Section A(Defining Variables): -
a. Defined x and a vector of different values of dx
b. Calculated Analytical Value using Analytical Formula
c. created "A" and "B" of Central and Skewed Forms ( "A" and "B" of AX = B)
d. Calculated "X" of Central and Skewed Forms using X = AB
B. Section B(Differentiating): -
a. Created A loop of Iteration of the length of dx vector
b. Selected a dx at each iteration
c. Created small functions for simplification of Calculations at each iteration
d. Calculated Central Difference and Skewed Differences using the Function defined above and X calculated in Section A.
e. Calculated Error generated per Iteration w.r.t Analytical Value Calculated in Section A and saved it in a Vector.
C. Section C(Plotting)
a. Plotted a log Graph between The Value of Error vs The Value of dx for all 3 Methods
b. Defined Proper Legends and Labels in the plot.
8. Code: -
% 4th Order 2nd Differentiation using Central and Both Skewed Schemes
clear all
close all
clc
%% Defining Variables
x = pi/3;
dx_all = x.*(10.^[-3:-1]);
analytical_val = -(2*exp(x)*sin(x))
A_crt_vec = [-2:1:2]';
A_rgt_vec = [0:5]';
A_lft_vec = [-5:0]';
A_crt = [ones(5,1),(A_crt_vec.^[1:4]).*(1./cumprod([1:4]))]';
A_rgt = [ones(6,1),(A_rgt_vec.^[1:5]).*(1./cumprod([1:5]))]';
A_lft = [ones(6,1),(A_lft_vec.^[1:5]).*(1./cumprod([1:5]))]';
B_crt = [0;0;1;0;0];
B_skw = [0;0;1;0;0;0];
X_crt = A_crtB_crt
X_rgt = A_rgtB_skw
X_lft = A_lftB_skw
%% Differentiating
for i=1:length(dx_all)
% Selecting h and Creating small Function for Ease
dx = dx_all(i);
f_mi_5 = exp(x-5*dx)*cos(x-5*dx);
f_mi_4 = exp(x-4*dx)*cos(x-4*dx);
f_mi_3 = exp(x-3*dx)*cos(x-3*dx);
f_mi_2 = exp(x-2*dx)*cos(x-2*dx);
f_mi_1 = exp(x-dx)*cos(x-dx);
f_x = exp(x)*cos(x);
f_pl_1 = exp(x+dx)*cos(x+dx);
f_pl_2 = exp(x+2*dx)*cos(x+2*dx);
f_pl_3 = exp(x+3*dx)*cos(x+3*dx);
f_pl_4 = exp(x+4*dx)*cos(x+4*dx);
f_pl_5 = exp(x+5*dx)*cos(x+5*dx);
% Creating Formula and Executing it
crt_fn_vec = [f_mi_2,f_mi_1,f_x,f_pl_1,f_pl_2];
skw_rgt_fn_vec = [f_x,f_pl_1,f_pl_2,f_pl_3,f_pl_4,f_pl_5];
skw_lft_fn_vec = [f_mi_5,f_mi_4,f_mi_3,f_mi_2,f_mi_1,f_x];
dif_crt = (crt_fn_vec*X_crt)/(dx^2);
dif_rgt = (skw_rgt_fn_vec*X_rgt)/(dx^2);
dif_lft = (skw_lft_fn_vec*X_lft)/(dx^2);
% Storing Errors
err_crt(i) = abs(analytical_val - dif_crt);
err_rgt(i) = abs(analytical_val - dif_rgt);
err_lft(i) = abs(analytical_val - dif_lft);
end
%% Plotting OUTPUT
loglog(dx_all,err_crt,dx_all,err_rgt,dx_all,err_lft)
xlabel('Value of dx','FontSize',15)
ylabel('Value of Error','FontSize',15)
legend('Central Difference','Skewed Right-Side Difference','Skewed Left-Side Difference')
9. OUTPUTS Generated on Running the Code: -
A. Command Window
B. Plot OUTPUT
10. Usefulness of Skewed Difference Methods: -
Skewed Schemes are Generally useful where the Information is flowing from one direction then the Correct calculations can only be developed by points on one side, as the next value thus defined is required to be developed using the values just achieved. To explain this I'm using the example Below.
Example,
In this example, if properties at points A and B are available and the Value of C is to be determined such that difference between each point is dx then,
Using Taylor Series, ϕC=ϕB+(∂ϕ∂x)Bdx
Now, As properties at points A and B are only Known So to determine (∂ϕ∂x)B
Skewed Left-Side Difference Method is used, (∂ϕ∂x)B=ϕB-ϕAdx
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 10 - Heat Transfer Analysis on BTMS for 4X2 Battery Set using Ansys
AIM:- A. To Perform a Heat Transfer Analysis on A battery set by Inlet Velocities and Gap Between the Batteries. B. The Explain the Relevant Results Generated by the Analysis. Given:- A. The Battery Set Geometry: - The Following are the Parameters for the Battery Set: - i. The…
05 Nov 2022 03:19 PM IST
Week 9 - Parametric study on Gate valve.
AIM: - A. To Perform Simulation on the Gate Valve by Setting the Opening from 10% to 80% B. To Calculate the Mass Flow rate and the Flow Factor for each Case Given: - A. The Given CAD Models of Gate Valves: - …
31 Oct 2022 12:05 PM IST
Week 8 - Simulating Cyclone separator with Discrete Phase Modelling
AIM: - A. To Perform the Analysis of the Given Cyclone separator for different particle sizes and different inlet speeds. B. To Explain the relevant theories and to explain the generated results Given and Assumed: - A. The Geometry of the Given CAD Model: - B. Material and their Properties:…
30 Oct 2022 07:43 AM IST
Week 6 - CHT Analysis on a Graphics card
Problem Statement: - Perform a Steady State CHT analysis on the Given Graphic Card Model for 3 inlet Velocities 1 m/sec, 3 m/sec, and 5 m/sec for Course and Fine Mesh. Create an appropriate Mesh, define appropriate Materials for each Component and Perform a mesh-independent Study. Expected Results: - 1. Explain…
23 Oct 2022 08:49 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.