All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
TYLOR TABLE -Method and MATLAB code Date: - 19-01-2021 4th order approximations of the second-order derivative: - Our main aim to find the difference or absolute error between exact value and approximate values from three approximations.…
SHAIK SYDAVALI
updated on 20 Jan 2021
TYLOR TABLE -Method and MATLAB code Date: - 19-01-2021
4th order approximations of the second-order derivative: -
Exact value: -
Given function f(x) = y = e^(x)* cos(x)
dy/dx = e^(x)(-sin(x)) + (e^(x)*cos(x))
d2y/dx2 = -2*sin(x)*e^(x)
d2y/dx2|x=л/3 = -4.935745353035276 = Exact Value
Approximate values: -
4th order approximation of Central difference: -
No of Nodes = p+q-1
Where,
p – order of derivative
q – order of approximation
Δx2(ꝺ2f/ꝺx2) = a*f(i-2) + b*f(i-1) + c*f(i) + d*f(i+1) + e*f(i+2)
Where, a,b,c,d,e are coefficients
Δx2(ꝺ2f/ꝺx2) |
f(i) |
Δx*f'(i) |
Δx^2*f''(i) |
Δx^3*f'''(i) |
Δx^4*f''''(i) |
a*f(i-2) |
a |
-2a |
2a |
-4a/3 |
2a/3 |
b*f(i-1) |
b |
-b |
b/2 |
-b/6 |
b/24 |
c*f(i) |
c |
0 |
0 |
0 |
0 |
d*f(i+1) |
d |
d |
d/2 |
d/6 |
d/24 |
e*f(i+2) |
e |
2e |
4e/2 |
4e/3 |
2e/3 |
sum |
0 |
0 |
1 |
0 |
0 |
Table 1:- 2nd order derivative Tylor’s table for given function(central difference)
Code:-
%% central diffrence for 4th order approximation
u1=zeros(5);
u1(1,:)=[1,1,1,1,1];
u1(2,:)=[-2,-1,0,1,2];
u1(3,:)=[2,1/2,0,1/2,2];
u1(4,:)=[-4/3,-1/6,0,1/6,4/3];
u1(5,:)=[2/3,1/24,0,1/24,2/3];
v1=zeros(5,1);
v1(3)=1;
w1=inv(u1)*v1;
W1 =
a |
-0.08333 |
b |
1.333333 |
c |
-2.5 |
d |
1.333333 |
e |
-0.08333 |
4th order approximation of Skewed right sided difference: -
No of Nodes = p+q
Where,
p – order of derivative
q – order of approximation
Δx2(ꝺ2f/ꝺx2) = a*f(i) + b*f(i+1) + c*f(i+2) + d*f(i+3) + e*f(i+4) + g*f(i+5) ------------- 1
Where, a,b,c,d,e,g are coefficients
Δx2(ꝺ2f/ꝺx2) |
f(i) |
Δx*f'(i) |
Δx^2*f''(i) |
Δx^3*f'''(i) |
Δx^4*f''''(i) |
Δx^5*f'''''(i) |
a*f(i) |
a |
0 |
0 |
0 |
0 |
0 |
b*f(i+1) |
b |
b |
b/2 |
b/6 |
b/24 |
b/120 |
c*f(i+2) |
c |
2c |
2c |
4c/3 |
2c/3 |
32b/120 |
d*f(i+3) |
d |
3d |
9d/2 |
27d/6 |
81d/24 |
243d/120 |
e*f(i+4) |
e |
4e |
16e/2 |
64e/6 |
256e/24 |
1024e/120 |
g*f(i+5) |
g |
5g |
25g/2 |
125g/6 |
625g/24 |
3125g/120 |
sum |
0 |
0 |
1 |
0 |
0 |
0 |
Table 2: - 2nd order derivative Tylor’s table for given function (skewed right side)
Code:
%% Skewed RSD
u2=zeros(6);
u2(1,:)=[1,1,1,1,1,1];
u2(2,:)=[0,1,2,3,4,5];
u2(3,:)=[0,1/2,2,9/2,8,25/2];
u2(4,:)=[0,1/6,4/3,27/6,64/6,125/6];
u2(5,:)=[0,1/24,2/3,81/24,256/24,625/24];
u2(6,:)=[0,1/120,32/120,243/120,1024/120,3125/120];
v2=zeros(6,1);
v2(3)=1;
w2=inv(u2)*v2;
W2 =
a |
3.75 |
b |
-12.8333 |
c |
17.83333 |
d |
-13 |
e |
5.083333 |
g |
-0.83333 |
4th order approximation of Skewed left sided difference: -
No of Nodes = p+q
Where,
p – order of derivative
q – order of approximation
Δx2(ꝺ2f/ꝺx2) = a*f(i-5) + b*f(i-4) + c*f(i-3) + d*f(i-2) + e*f(i-1) + g*f(i) ---------- 2
Where, a,b,c,d,e,g are coefficients
Δx2(ꝺ2f/ꝺx2) |
f(i) |
Δx*f'(i) |
Δx^2*f''(i) |
Δx^3*f'''(i) |
Δx^4*f''''(i) |
Δx^5*f'''''(i) |
a*f(i-5) |
a |
-5a |
25a/2 |
-125a/6 |
625a/24 |
-3125a/120 |
b*f(i-4) |
b |
-4b |
16b/2 |
-64b/6 |
256b/24 |
-1024b/120 |
c*f(i-3) |
c |
-3c |
9c/2 |
-27c/6 |
81c/24 |
-243c/120 |
d*f(i-2) |
d |
-2d |
2d |
-4d/3 |
2d/3 |
-32d/20 |
e*f(i-1) |
e |
-e |
e/2 |
-e/6 |
e/24 |
-e/120 |
g*f(i) |
g |
0 |
0 |
0 |
0 |
0 |
sum |
0 |
0 |
1 |
0 |
0 |
0 |
Table 2: - 2nd order derivative Tylor’s table for given function (skewed left side)
Code:
%% Skewed LSD
u3=zeros(6);
u3(1,:)=[1,1,1,1,1,1];
u3(2,:)=[-5,-4,-3,-2,-1,0];
u3(3,:)=[25/2,8,9/2,2,1/2,0];
u3(4,:)=[-125/6,-64/6,-27/6,-4/3,-1/6,0];
u3(5,:)=[625/24,256/24,81/24,2/3,1/24,0];
u3(6,:)=[-3125/120,-1024/120,-243/120,-32/120,-1/120,0];
v3=zeros(6,1);
v3(3)=1;
w3=inv(u3)*v3;
W3 =
a |
-0.83333 |
b |
5.083333 |
c |
-13 |
d |
17.83333 |
e |
-12.8333 |
g |
3.75 |
Steps to find desire output: -
Function code: -
function y=numerical(x)
y =exp(x)*cos(x);
end
Code: -
%%
x=pi/3;
dx=linspace(0.1,0.01,50);
exact_value = -2*sin(x)*exp(x);
for i=1:length(dx)
f_central(i)=[w1(1)*numerical(x-2*dx(i))+w1(2)*numerical(x-dx(i))+w1(3)*numerical(x)+w1(4)*numerical(x+dx(i))+w1(5)*numerical(x+2*dx(i))]/(dx(i)^2);
f_RSD(i)=[w2(1)*numerical(x)+w2(2)*numerical(x+dx(i))+w2(3)*numerical(x+2*dx(i))+w2(4)*numerical(x+3*dx(i))+w2(5)*numerical(x+4*dx(i))+w2(6)*numerical(x+5*dx(i))]/(dx(i)^2);
f_LSD(i)=[w3(1)*numerical(x-5*dx(i))+w3(2)*numerical(x-4*dx(i))+w3(3)*numerical(x-3*dx(i))+w3(4)*numerical(x-2*dx(i))+w3(5)*numerical(x-dx(i))+w3(6)*numerical(x)]/(dx(i)^2);
a(i)=abs(f_central(i)-exact_value);
b(i)=abs(f_RSD(i)-exact_value);
c(i)=abs(f_LSD(i)-exact_value);
end
Code:
figure(1)
loglog(dx,a,'-r','linewidth',3);
hold on;
loglog(dx,b,'-k','linewidth',3);
hold on;
loglog(dx,c,'-b','linewidth',3);
grid on;
xlabel('dx');
ylabel('Absolute error');
legend('Central Difference of 4th Order','Skewed Right Side Difference of 4th Order','Skewed Left Side Difference of 4th Order');
title('Consistency of different scheme');
OUTPUT GRAPH: -
Proof of Skewed schemes are 4th order approximation: -
Skewed right sided difference: -
Δx2(ꝺ2f/ꝺx2) = a*f(i) + b*f(i+1) + c*f(i+2) + d*f(i+3) + e*f(i+4) + g*f(i+5)
L.H.S = a*f(i) + b*[f(i) + Δx*f’(i) + Δx2 * f’’(i)/2! + Δx3 * f’’’(i)/3! + Δx4 * f’’’’(i)/4! + Δx5 * f’’’’’(i) + Δx6 * f’’’’’’(i)/6! ………..etc] + c*[f(i) + 2Δx*f’(i) + (2Δx)2 * f’’(i)/2! + (2Δx)3 * f’’’(i)/3! + (2Δx)4 * f’’’’(i)/4! + (2Δx)5 * f’’’’’(i) + (2Δx)6 * f’’’’’’(i)/6! ……… etc] + d*[f(i) + 3Δx*f’(i) + (3Δx)2 * f’’(i)/2! + (3Δx)3 * f’’’(i)/3! + (3Δx)4 * f’’’’(i)/4! + (3Δx)5 * f’’’’’(i) + (3Δx)6 * f’’’’’’(i)/6! ……… etc] + e*[f(i) + 4Δx*f’(i) + (4Δx)2 * f’’(i)/2! + (4Δx)3 * f’’’(i)/3! + (4Δx)4 * f’’’’(i)/4! + (4Δx)5 * f’’’’’(i) + (4Δx)6 * f’’’’’’(i)/6! ……… etc] + g*[f(i) + 5Δx*f’(i) + (5Δx)2 * f’’(i)/2! + (5Δx)3 * f’’’(i)/3! + (5Δx)4 * f’’’’(i)/4! + (5Δx)5 * f’’’’’(i) + (5Δx)6 * f’’’’’’(i)/6! ……… etc]
LHS = (a+b+c+d+e+g) * f(i) + (b+2c+3d+4e+5g) *Δx *f’(i) + (b/2+2c+9d/2+8e+25g/2) *Δx2 *f’’(i) + (b/6+8c/6+27d/6+64e/6+125g/6) *Δx3 *f’’’(i) + (b+16c+81d+256e+625g) *(Δx4/24)*f’’’’(i) + (b+32c+243d+1024e+3125g) *(Δx5/120) *f’’’’’(i) + (b+64c+729d+4096e+15625g) *(Δx6/720) *f’’’’’’(i) + …………….. etc
LHS = Δx2(ꝺ2f/ꝺx2) = I * Δx2 *f’’(i) + J * Δx6 * f’’’’’’(i)
Where I and J are the constant non zero values after substituting the values of coefficients .
ꝺ2f/ꝺx2 = = I *f’’(i) + J * Δx4 * f’’’’’’(i)
Skewed Left sided difference: -
Δx2(ꝺ2f/ꝺx2) = a*f(i-5) + b*f(i-4) + c*f(i-3) + d*f(i-2) + e*f(i-1) + g*f(i)
L.H.S = g*f(i) + e*[f(i) - Δx*f’(i) + Δx2 * f’’(i)/2! - Δx3 * f’’’(i)/3! + Δx4 * f’’’’(i)/4! - Δx5 * f’’’’’(i) + Δx6 * f’’’’’’(i)/6! ………..etc] + d*[f(i) - 2Δx*f’(i) + (2Δx)2 * f’’(i)/2! - (2Δx)3 * f’’’(i)/3! + (2Δx)4 * f’’’’(i)/4! - (2Δx)5 * f’’’’’(i) + (2Δx)6 * f’’’’’’(i)/6! ……… etc] + c*[f(i) - 3Δx*f’(i) + (3Δx)2 * f’’(i)/2! - (3Δx)3 * f’’’(i)/3! + (3Δx)4 * f’’’’(i)/4! - (3Δx)5 * f’’’’’(i) + (3Δx)6 * f’’’’’’(i)/6! ……… etc] + b*[f(i) - 4Δx*f’(i) + (4Δx)2 * f’’(i)/2! - (4Δx)3 * f’’’(i)/3! + (4Δx)4 * f’’’’(i)/4! - (4Δx)5 * f’’’’’(i) + (4Δx)6 * f’’’’’’(i)/6! ……… etc] + a*[f(i) - 5Δx*f’(i) + (5Δx)2 * f’’(i)/2! - (5Δx)3 * f’’’(i)/3! + (5Δx)4 * f’’’’(i)/4! - (5Δx)5 * f’’’’’(i) + (5Δx)6 * f’’’’’’(i)/6! ……… etc]
LHS = Δx2(ꝺ2f/ꝺx2) = I * Δx2 *f’’(i) + J * Δx6 * f’’’’’’(i)
Where I and J are the constant non zero values after substituting the values of coefficients .
ꝺ2f/ꝺx2 = = I *f’’(i) + J * Δx4 * f’’’’’’(i)
Advantages of Skewed schemes over Central difference schemes: -
These skewed schemes are very important at finding the first point information means after boundary condition point. In figure consider domain and ‘A’, ‘B’ are boundary point where we have information. Then, by using skewed schemes we can able to find information at point ‘B’ and ‘G’ very easily but with central difference we can’t.
%%Function programme
function y=numerical(x)
y =exp(x)*cos(x);%given function in problem
end
%%function file and main programme file should be in same folder
%%main programme
clear all;
close all;
clc;
%% central diffrence for 4th order approximation
u1=zeros(5);%defining null matrix of size 5X5
u1(1,:)=[1,1,1,1,1];
u1(2,:)=[-2,-1,0,1,2];
u1(3,:)=[2,1/2,0,1/2,2];
u1(4,:)=[-4/3,-1/6,0,1/6,4/3];
u1(5,:)=[2/3,1/24,0,1/24,2/3];
v1=zeros(5,1);
v1(3)=1;
w1=inv(u1)*v1;%by using inverse operator we can able to find coefficients
%% Skewed RSD
u2=zeros(6);%defining null matrix of size 6X6
u2(1,:)=[1,1,1,1,1,1];
u2(2,:)=[0,1,2,3,4,5];
u2(3,:)=[0,1/2,2,9/2,8,25/2];
u2(4,:)=[0,1/6,4/3,27/6,64/6,125/6];
u2(5,:)=[0,1/24,2/3,81/24,256/24,625/24];
u2(6,:)=[0,1/120,32/120,243/120,1024/120,3125/120];
v2=zeros(6,1);
v2(3)=1;
w2=inv(u2)*v2;%by using inverse operator we can able to find coefficients
%%
x=pi/3;
dx=linspace(0.1,0.01,50);
exact_value = -2*sin(x)*exp(x);
for i=1:length(dx)
f_central(i)=[w1(1)*numerical(x-2*dx(i))+w1(2)*numerical(x-dx(i))+w1(3)*numerical(x)+w1(4)*numerical(x+dx(i))+w1(5)*numerical(x+2*dx(i))]/(dx(i)^2);%assigning values of coefficients and finding truncation error
f_RSD(i)=[w2(1)*numerical(x)+w2(2)*numerical(x+dx(i))+w2(3)*numerical(x+2*dx(i))+w2(4)*numerical(x+3*dx(i))+w2(5)*numerical(x+4*dx(i))+w2(6)*numerical(x+5*dx(i))]/(dx(i)^2);%assigning values of coefficients and finding truncation error
f_LSD(i)=[w3(1)*numerical(x-5*dx(i))+w3(2)*numerical(x-4*dx(i))+w3(3)*numerical(x-3*dx(i))+w3(4)*numerical(x-2*dx(i))+w3(5)*numerical(x-dx(i))+w3(6)*numerical(x)]/(dx(i)^2);%assigning values of coefficients and finding truncation error
a(i)=abs(f_central(i)-exact_value);
b(i)=abs(f_RSD(i)-exact_value);
c(i)=abs(f_LSD(i)-exact_value);
end
%%
figure(1)
loglog(dx,a,'-r','linewidth',3);%%using log plot so that we can able to see very minimum differenece in residuals
hold on;
loglog(dx,b,'-k','linewidth',3);
hold on;
loglog(dx,c,'-b','linewidth',3);
grid on;
xlabel('dx');
ylabel('Absolute error');
legend('Central Difference of 4th Order','Skewed Right Side Difference of 4th Order','Skewed Left Side Difference of 4th Order');
title('Consistency of different scheme');
%%
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 4 - CHT Analysis on Exhaust port
CHT ANALYSIS ON EXHAUST PORT About CHT analysis: - CHT means Conjugate Heat Transfer which can tell combination of heat transfer in solids and fluids. This numerical analysis will give brief idea about conduction, convection and radiation or coupling of anyone of these three. The CHT analysis is used in process…
21 Jun 2021 12:26 PM IST
Week 3 - External flow simulation over an Ahmed body.
EXTERNAL FLOW SIMULATION OVER AN AHMED BODY AHMED BODY: - Ahmed body is a simplified car, used in automotive industry to investigate the flow analysis and find the wake flow around the body. This is made up of round front part, a moveable slant plane in ear…
20 Jun 2021 03:05 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.