All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Object: Derive the following 4th order approximation of the second-order derivative using:- Central difference Skewed right-sided difference Skewed left-sided difference Also, prove that your skewed schemes are fourth-order accurate. Write a program in Matlab to evaluate the second-order derivative of…
KURUVA GUDISE KRISHNA MURHTY
updated on 18 Jul 2022
Object:
Derive the following 4th order approximation of the second-order derivative using:-
Also, prove that your 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 that you have derived.
Answer:
Derivation of the 4th order approximation of the Second-Order Derivative
1)Using the Central Difference method:
Since we’re deriving using central difference; our numerical stencil will look like.
Here, we’re computing 4th order approximation at point (i), where we take information from the four-point surrounding (i); i.e. we’re going to take two points on the left of (i) and two points on the right of (i). Let those points be (i-2), (i-1), (i+1), and (i+2) and the distance between each of them is (Δx).(∆x). Our numerical stencil will look like as shown in the above figure.
Based on the above stencil our hypothesis equation will be:-
∂2u∂x2=af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2).........(1)∂2u∂x2=af(i−2)+bf(i−1)+cf(i)+df(i+1)+ef(i+2).........(1)
In order to find the values of coefficient(a,b,c,d,e),(a,b,c,d,e),we’re going to use the Taylor table method. Writing Taylor series expansion for each term of equation (1) as:-
(a)f(i-2)=(a)f(i)-(a)f′(i)(2)Δx1!+((a)f′′(i)(2)Δx)22!-((a)f′′′(i)(2)Δx)33!+((a)f′′′′(i)(2)Δx)44!-((a)f′′′′′(i)(2)Δx)55!+((a)f′′′′′′(i)(2)Δx)66!+....
(b)f(i-1)=(b)f(i)-(b)f′(i)Δx1!+((b)f′′(i)Δx)22!-((b)f′′′(i)Δx)33!+((b)f′′′′(i)Δx)44!-((b)f′′′′′(i)Δx)55!+((b)f′′′′′′(i)Δx)66!+....
(c)f(i)=(c)f(i)
(d)f(i+1)=(d)f(i)-(d)f′(i)Δx1!+((d)f′′(i)Δx)22!-((d)f′′′(i)Δx)33!+((d)f′′′′(i)Δx)44!-((d)f′′′′′(i)Δx)55!+((d)f′′′′′′(i)Δx)66!+....
(e)f(i+2)=(e)f(i)-(e)f′(i)(2)Δx1!+((e)f′′(i)(2)Δx)22!-((e)f′′′(i)(2)Δx)33!+((e)f′′′′(i)(2)Δx)44!-((e)f′′′′′(i)(2)Δx)55!+((e)f′′′′′′(i)(2)Δx)66!+....
By arranging the above Taylor series expansions in Taylor table; we get:-
Note: Only for the first five terms we assume our hypothesis. That’s why we can’t say about the last two terms.
Here we have five unknowns, so, we have to solve five equations and get values of coefficients (a,b,c,d,e).(a,b,c,d,e). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of `f''(i) is equal to 1, andf(i),f′(i),f′'(i),f′''(i),f′'''(i)f(i),f′(i),f′′(i),f′′′(i),f′′′′(i) are equal to 0; because we want to calculate the second-order derivative, f′'(i).f′′(i).
Therefore, the five equations are:
a+b+c+d+e=0a+b+c+d+e=0 ……….. (I)
−2a−b+0+d+2e=0-2a-b+0+d+2e=0 ……….. (II)
2a+b2+0+d2+2e=12a+b2+0+d2+2e=1 ……….. (III)
−8a6−b6+0+d6+8e6=0-8a6-b6+0+d6+8e6=0 ……….. (IV)
16a24+b24+0+d24+16e24=016a24+b24+0+d24+16e24=0 ……….. (V)
To get the solution of the above equations, we have to solve the above equations in matrix form; AX=B.
After solving the above matrix, we get the values of all the coefficients as:
a=−0.083333a=-0.083333
b=1.333333b=1.333333
c=−2.500000c=-2.500000
d=1.333333d=1.333333
e=−0.083333e=-0.083333
Here, we can easily notice that a=e,a=e, and b=d.b=d.
Now, on dividing both side of my hypothesis equation (1) by (Δx2)(∆x2); we get:
∂2u∂x2=af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2)Δx2
Now, on dividing both side of my hypothesis equation (1) by (Δx2)(∆x2); we get:
After putting the values of all the coefficients (a,b,c,d,e)(a,b,c,d,e) in the above equation, we will get the fourth-order central difference approximation for the second-order derivative.
∂2u∂x2=(-0.083333)f(i-2)+(1.3333333)f(i-1)+(-2.500000)f(i)+(1.3333333)f(i+1)+(-0.083333)f(i+2)Δx2
Now, from our Taylor tabel:
∂2u∂x2=(a+b+c+0+d+e)f(i)+(-2a-b+0+d+2e)f′(i)Δx+(2a+12b+0+12d+2e)f′′(i)Δx2+(-86a-16b+0+16d+86e)f′′′(i)Δx3+(1624a+124b+0+124d+1624e)f′′′′(i)Δx4+(-32120a-1120b+0+1120d+32120e)f′′′′′(i)Δx5+(64240a+1240b+0+1240d+64240e)f′′′′′′(i)Δx6
To get second-order derivative the coefficient of f''(i)f′′(i) has to be 1. And as we want approximation for the second-order derivative, so, the term f(i),f′(i),f′''(i),f′'''(i)f(i),f′(i),f′′′(i),f′′′′(i) will have to ignore or set to ‘0’ in the above equation. On substituting the values of (I), (II), (IV), and (V) in the above equation; we’ll get:
∂2u∂x2=(2a+12b+0+12d+2e)f′′(i)Δx2+(-32120a-1120b+0+1120d+32120e)f′′′′′(i)Δx5+(64240a+1240b+0+1240d+64240e)f′′′′′′(i)Δx6
On dividing the above equation by (Δx^2), we get:
∂2u∂x2=(2a+12b+0+12d+2e)f′′(i)+(64240a+1240b+0+1240d+64240e)f′′′′′′(i)Δx4
In the above equation, the term Δx4∆x4 denotes the truncation error. Here, we can see that the order of the truncation error; [O(Δx4∆x4)] is ‘4’. Since we know that the order of approximation is defined by the truncation error term. Therefore, we can say that our central difference scheme is 4th order accurate.
After putting the value of (a,b,c,d,e)(a,b,c,d,e) in the above equation, the final equation looks like this:
∂2u∂x2=(2(-0.083333)+12(1.333333)+12(1.333333)+2(0.0833333))f′′(i)+(64240(-0.083333)+1240(1.333333)+1240(1.333333)+64240(0.0833333))f′′′′′′(i)Δx4
2)Using Skewed Right-Sided Difference:
To derive 4th order skewed right-sided difference at point (i) of function. Since we’re using the skewed right-sided method, here we have to define five points on the right of (i). Let those points be (i+1), (i+2), (i+3), (i+4), and (i+5); with a spacing of Δx∆x each.
The numerical stencil will look.
According to the above stencil, our hypothesis equation will be:
∂2u∂x2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)
In order to find the values of coefficients (a,b,c,d,e,g),(a,b,c,d,e,g), we’re going to use the Taylor table method.
Writing Taylor series expansion for each term of equation (1) as:-
(a)f(i)=(a)f(i)
(b)f(i+1)=(b)f(i)+(b)f′(i)Δx1!+(b)f′′(i)(Δx)22!+(b)f′′′(i)(Δx)33!+(b)f′′′′(i)(Δx)44!+(b)f′′′′′(i)(Δx)55!+(b)f′′′′′′(i)(Δx)66!+....
(c)f(i+2)=(c)f(i)+(c)f′(i)(2)Δx1!+(c)f′′(i)(2Δx)22!+(c)f′′′(i)(2Δx)33!+(c)f′′′′(i)(2Δx)44!+(c)f′′′′′(i)(2Δx)55!+(c)f′′′′′′(i)(2Δx)66!+...
(d)f(i+3)=(d)f(i)+(d)f′(i)(3)Δx1!+(d)f′′(i)(3Δx)22!+(d)f′′′(i)(3Δx)33!+(d)f′′′′(i)(3Δx)44!+(d)f′′′′′(i)(3Δx)55!+(d)f′′′′′′(i)(3Δx)66!+...
(e)f(i+4)=(e)f(i)+(e)f′(i)(4Δx)1!+(e)f′′(i)(4Δx)22!+(e)f′′′(i)(4Δx)33!+(e)f′′′′(i)(4Δx)44!+(e)f′′′′′(i)(4Δx)55!+(e)f′′′′′′(i)(4Δx)66!+...
(g)f(i+5)=(g)f(i)+(g)f′(i)(5Δx)1!+(g)f′′(i)(5Δx)22!+(g)f′′′(i)(5Δx)33!+(g)f′′′′(i)(5Δx)44!+(g)f′′′′′(i)(5Δx)55!+(g)f′′′′′′(i)(5Δx)66!+...
By arranging the above Taylor series expansions in Taylor table; we get:-
Only for the first six terms, we assume our hypothesis. That’s why we can’t say about the last term.
Here we have six unknowns, so, we have to solve six equations and get values of coefficients (a,b,c,d,e,g).(a,b,c,d,e,g). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of f′'(i)f′′(i) is equal to 1, and f(i),f′(i),f′'(i),f′''(i),f′'''(i),f'''''(i)f(i),f′(i),f′′(i),f′′′(i),f′′′′(i),f′′′′′(i) is equal to 0; because we want to calculate the second-order derivative, f''(i).f′′(i).
Therefore, the six equations are:-
a+b+c+d+e+g=0a+b+c+d+e+g=0 ……….. (I)
0+b+2c+3d+4e+5g=00+b+2c+3d+4e+5g=0 ……….. (II)
0+b2+2c+9d2+8e+25g2=10+b2+2c+9d2+8e+25g2=1 ……….. (III)
0+b6+8c6+27d6+64e6+125g6=00+b6+8c6+27d6+64e6+125g6=0 ……….. (IV)
0+b24+16c24+81d24+256e24+625g24=00+b24+16c24+81d24+256e24+625g24=0 ……….. (V)
0+b120+32c120+243d120+1024e120+3125g120=00+b120+32c120+243d120+1024e120+3125g120=0 ……….. (VI)
To get the solution of the above equations, we have to solve the above equations in matrix form; AX=B.
After solving the above matrix, we get the values of all the coefficients as:-
a=3.75000a=3.75000
b=−12.83333b=-12.83333
c=17.83333c=17.83333
d=−13.00000d=-13.00000
e=5.08333e=5.08333
g=−0.83333g=-0.83333
Now, dividing both side of my hypothesis equation (1) by (Δx^2); we get:
∂2u∂x2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)Δx2
After putting the values of all the coefficients (a,b,c,d,e,g)(a,b,c,d,e,g) in the above equation, we will get the fourth-order skewed right-sided difference approximation for second-order derivative.
∂2u∂x2=(3.75000)f(i)+(-12.83333)f(i+1)+(17.83333)f(i+2)+(-13.00000)f(i+3)+(5.083333)f(i+4)+(-0.83333)f(i+5)Δx2
Now, from our Taylor tabel:
∂2u∂x2=(a+b+c+0+d+e)f(i)+(0+b+2c+3d+4e+5g)f′(i)Δx+(0+b2+4c2+9d2+16e2+25g2)f′′(i)Δx2+(0+b6+8c6+27d6+64e2+125g6)f′′′(i)Δx3+(0+b24+16c24+81d24+256e24+625g24)f′′′′(i)Δx4+(0+b120+32c120+243d120+1024e120+3125g120)f′′′′′(i)Δx5+(0+b720+64c720+729d720+4096e720+15625g720)f′′′′′′(i)Δx6
To get second-order derivative the coefficient of f''(i)f′′(i) has to be 1. And as we want approximation for the second-order derivative, so, the term f(i),f′(i),f′''(i),f′'''(i)f(i),f′(i),f′′′(i),f′′′′(i) will have to ignore or set to ‘0’ in the above equation. On substituting the values of (I), (II), (IV), and (V) in the above equation; we’ll get:
∂2u∂x2=(0+b2+4c2+9d2+16e2+25g2)f′′(i)Δx2+(0+b720+64c720+729d720+4096e720+15625g720)f′′′′′′(i)Δx6
On dividing the above equation by (Δx2)(∆x2), we get:-
∂2u∂x2=(b2+2c+9d2+8e+25g2)f′′(i)+(b720+64c720+729d720+4096e720+15625g720)f′′′′′′(i)Δx4
As we discussed earlier also, the Δx^4 denotes the truncation error. Here we can see that order of the truncation error; [O(Δx^4)] is '4'. Since, we know that the order of approximation is defined by the truncation error term. Therefore, we can say that our skewed right-sided difference scheme is of 4th order accurate.
After putting the values of (a,b,c,d,e,g)(a,b,c,d,e,g) in the above equation, the final equation looks like this:-
∂2u∂x2=(-12.833332+2(17.83333)+9-13.000002+8(5.08333)+25-0.083332)f′′(i)+(-12.83333720+6417.83333720+729-13.00000720+40965.08333720+15625-0.08333720)f′′′′′′(i)Δx4
3)Using Skewed Left-Sided Difference:
To derive 4th order skewed left-sided difference at point (i) of function. Since we’re using the skewed left-sided method, here we have to define five points on the left of (i). Let those points be (i-1), (i-2), (i-3), (i-4), and (i-5); with a spacing of Δx^2 each.
The numerical stencil will look.
According to the above stencil, our hypothesis equation will be:
∂2u∂x2=af(i-5)+bf(i-4)+cf(i-3)+df(i-2)+ef(i-1)+gf(i)
To find the values of coefficients (a,b,c,d,e,g),(a,b,c,d,e,g), we’re going to use the Taylor table method.
Writing Taylor series expansion for each term of equation (1) as:-
(a)f(i-5)=(a)f(i)-(a)f′(i)(5Δx)1!+(a)f′′(i)(5Δx)22!-(a)f′′′(i)(5Δx)33!+(a)f′′′′(i)(5Δx)44!-(a)f′′′′′(i)(5Δx)55!+(a)f′′′′′′(i)(5Δx)66!+...
(b)f(i-4)=(b)f(i)-(b)f′(i)(4Δx)1!+(b)f′′(i)(4Δx)22!-(b)f′′′(i)(4Δx)33!+(b)f′′′′(i)(4Δx)44!-(b)f′′′′′(i)(4Δx)55!+(b)f′′′′′′(i)(4Δx)66!+...
(c)f(i-3)=(c)f(i)-(c)f′(i)(3Δx)1!+(c)f′′(i)(3Δx)22!-(c)f′′′(i)(3Δx)33!+(c)f′′′′(i)(3Δx)44!-(c)f′′′′′(i)(3Δx)55!+(c)f′′′′′′(i)(3Δx)66!+...
(d)f(i-2)=(d)f(i)-(d)f′(i)(2Δx)1!+(d)f′′(i)(2Δx)22!-(d)f′′′(i)(2Δx)33!+(d)f′′′′(i)(2Δx)44!-(d)f′′′′′(i)(2Δx)55!+(d)f′′′′′′(i)(2Δx)66!+...
(e)f(i-1)=(e)f(i)-(e)f′(i)(Δx)1!+(e)f′′(i)(Δx)22!-(e)f′′′(i)(Δx)33!+(e)f′′′′(i)(Δx)44!-(e)f′′′′′(i)(Δx)55!+(e)f′′′′′′(i)(Δx)66!+...
(g)f(i)=(g)f(i)
By arranging the above Taylor series expansions in Taylor table; we get:-
Only for the first six terms, we assume our hypothesis. That’s why we can’t say about the last term.
Here we have six unknowns, so, we have to solve six equations and get values of coefficients (a,b,c,d,e,g).(a,b,c,d,e,g). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of f′'(i)f′′(i) is equal to 1, and f(i),f′(i),f′'(i),f′''(i),f′'''(i),f'''''(i)f(i),f′(i),f′′(i),f′′′(i),f′′′′(i),f′′′′′(i) is equal to 0; because we want to calculate the second-order derivative, f''(i).f′′(i).
Therefore, the six equations are:-
a+b+c+d+e+g=0a+b+c+d+e+g=0 ……….. (I)
−5a−4b−3c−2d−e+0=0-5a-4b-3c-2d-e+0=0 ……….. (II)
25a2+8b+9c2+2d+e2+0=125a2+8b+9c2+2d+e2+0=1 ……….. (III)
625a24+256b24+81c24+16c24+e24+0=0625a24+256b24+81c24+16c24+e24+0=0 ……….. (V)
−3125a120−1024b120−243c120−32d120−e120+0=0-3125a120-1024b120-243c120-32d120-e120+0=0 ……….. (VI)
To get the solution of the above equations, we have to solve the above equations in matrix form; AX=B.
After solving the above matrix, we get the values of all the coefficients as:-
a=−0.83333a=-0.83333
b=5.08333b=5.08333
c=−13.00000c=-13.00000
d=17.83333d=17.83333
e=−12.83333e=-12.83333
g=3.75000g=3.75000
Now, dividing both side of my hypothesis equation (1) by (Δx^2); we get:
∂2u∂x2=af(i-5)+bf(i-4)+cf(i-3)+df(i-2)+ef(i-1)+gf(i)Δx2
After putting the values of all the coefficients (a,b,c,d,e,g)(a,b,c,d,e,g) in the above equation, we will get the fourth-order skewed right-sided difference approximation for second-order derivative.
∂2u∂x2=(-0.83333)f(i-5)+(5.08333)f(i-4)+(-13.00000)f(i-3)+(17.83333)f(i-2)+(-12.83333)f(i-1)+(3.75000)f(i)Δx2
Now,form our Taylor table:-
∂2u∂x2=(a+b+c+0+d+e)f(i)+(-5a-4b-3c-2d-e+0)f′(i)Δx+(25a2+8b+9c2+2d+e2+0)f′′(i)Δx2+(-125a6-64b6+27c6-8d6-e2+0)f′′′(i)Δx3+(625a24+256b24+81c24+16d24+e24+0)f′′′′(i)Δx4+(-3125a120-1024b120-243c120-32d120-e120+0)f′′′′′(i)Δx5+(15625a720+4096b720+729c720+64d720+e720+0)f′′′′′′(i)Δx6
To get second-order derivative the coefficient of f''(i)f′′(i) has to be 1. And as we want approximation for the second-order derivative, so, the term f(i),f′(i),f′''(i),f′'''(i),f'''''(i)f(i),f′(i),f′′′(i),f′′′′(i),f′′′′′(i) will have to ignore or set to 0 in the above equation. On substituting the values of (I), (II), (IV), (V), and (VI) in the above equation; we’ll get:
∂2u∂x2=(25a2+8b+9c2+2d+e2+0)f′′(i)Δx2+(15625a720+4096b720+729c720+64d720+e720+0)f′′′′′′(i)Δx6
On dividing the above equation byΔx^2,; we get:-
∂2u∂x2=(25a2+8b+9c2+2d+e2+0)f′′(i)+(15625a720+4096b720+729c720+64d720+e720+0)f′′′′′′(i)Δx4
On dividing the above equation byΔx^2,; we get:-
As we discussed earlier also, the Δx4∆x4 denotes the truncation error. Here we can see that order of the truncation error; [O(Δx4)][O(∆x4)] is ‘4’. Since, we know that the order of approximation is defined by the truncation error term. Therefore, we can say that our skewed left-sided difference scheme is of 4th order accurate.
After putting the values of (a,b,c,d,e,g)(a,b,c,d,e,g) in the above equation, the final equation looks like this:-
∂2u∂x2=(25-0.8333332+8(5.08333)+9-13.000002+2(17.83333)+-12.833332+0)f′′(i)+(15625-0.083333720+40965.08333720+729-13.00000720+6417.83333720+-12.83333720)f′′′′′′(i)Δx4
Program in MATLAB to Evaluate the Second-Order Derivative of the analytical function exp(x)*cos(x) and compare it with the numerical approximation that we have derived above
Firstly we’re going to write programs to develop functions for central, skewed right-sided and skewed left-sided errors at a particular point (x, dx), where dx represents spacing in between each node. These functions will help us to calculate errors over the range of ‘dx’. With the help of code ‘function out’ we’re going to make function; which we save in directory and call according to our need in the main program (make sure to save the main program in the same directory in which your function is saved).
Function for central difference 4th order error at particular spacing ‘dx’:
% Creating function for the 4th order approximation of the second-order; derivative using central difference;
function error_central_differencing = central_difference(x,dx)
% Analytical function f(x) = exp(x)*cos(x);
% f''(x) = -2*exp(x)*sin(x);
analytical_derivative = -2*exp(x)*sin(x);
% values of coefficients calculated from our Taylor table;
a=-0.083333;
b=1.333333;
c=-2.500000;
d=1.333333;
e=-0.083333;
% numerical derivative;
% central differencing =
% ((a*f(x-2*dx))+(b*f(x-dx))+(c*f(x))+(d*f(x+dx))+(e*f(x+2*dx)))/dx^2;
%central difference fourth order approximation;
central_differencing_fourth_order_approx = ((a*exp(x-2*dx)*cos(x-2*dx))+(b*exp(x-dx)*cos(x-dx))+(c*exp(x)*cos(x))+(d*exp(x+dx)*cos(x+dx))+(e*exp(x+2*dx)*cos(x+2*dx)))/dx^2;
error_central_differencing = abs(central_differencing_fourth_order_approx-analytical_derivative);
end
Function for skewed right-sided difference 4th order error at particular spacing ‘dx’:
% Creating function for the 4th order approximation of the second-order derivative using skewed right-sided difference;
function error_skewed_right_sided=skewed_right_sided(x,dx)
% analytical function f(x)=exp(x)*cos(x);
%f''(x)=-2*exp(x)*sin(x);
analytical_derivative=-2*exp(x)*sin(x);
%values of coefficients calculated from our Taylor table;
a=3.75000;
b=-12.83333;
c=17.83333;
d=-13.00000;
e=5.08333;
g=-0.83333;
%numerical derivative;
%skewed right-sided differencing=((a*f(x))+(b*f(x+dx))+(c*f(x+2*dx))+(d*f(x+3*dx))+(e*f(x+4*dx))+(g*f(x+5*dx)))/dx^2;
%skewed right-sided fourth order approximation;
skewed_right_sided_fourth_order_approx=((a*exp(x)*cos(x))+(b*exp(x+dx)*cos(x+dx))+(c*exp(x+2*dx)*cos(x+2*dx))+(d*exp(x+3*dx)*cos(x+3*dx))+(e*exp(x+4*dx)*cos(x+4*dx))+(g*exp(x+5*dx)*cos(x+5*dx)))/dx^2;
error_skewed_right_sided=abs(skewed_right_sided_fourth_order_approx-analytical_derivative);
end
Function for skewed left-sided difference 4th order error at particular spacing ‘dx’:
% Creating function for the 4th order approximation of the second-order derivative using skewed left-sided difference;
function error_skewed_left_sided=skewed_left_sided(x,dx)
% analytical function f(x)=exp(x)*cos(x);
%f''(x)=-2*exp(x)*sin(x);
analytical_derivative=-2*exp(x)*sin(x);
%values of coefficients calculated from our Taylor table;
a=-0.83333;
b=5.08333;
c=-13.00000;
d=17.83333;
e=-12.83333;
g=3.75000;
%numerical derivative;
%skewed left-sided differencing=((a*f(x-5*dx))+(b*f(x-4*dx))+(c*f(x-3*dx))+(d*f(x-2*dx))+(e*f(x-dx))+(g*f(x)))/dx^2;
%skewed left-sided fourth order approximation;
skewed_left_sided_fourth_order_approx=((a*exp(x-5*dx)*cos(x-5*dx))+(b*exp(x-4*dx)*cos(x-4*dx))+(c*exp(x-3*dx)*cos(x-3*dx))+(d*exp(x-2*dx)*cos(x-2*dx))+(e*exp(x-dx)*cos(x-dx))+(g*exp(x)*cos(x)))/dx^2;
error_skewed_left_sided=abs(skewed_left_sided_fourth_order_approx-analytical_derivative);
end
After creating the above functions, we save our main program in the same directory in which we have saved our three functions; central_difference, skewed_right_sided, skewed_left_sided.
For now, we’re going to create an array for the range of ‘dx’. We’ll use ‘for loop’ over the range of ‘dx’ and using the functions central, skewed right-sided and skewed left-sided difference 4th order error at a given point (x, dx), we’ll get the errors for a range of ‘dx’ and also we’re going to plot the graph between ‘error’ vs. ‘dx’ for central, skewed right-sided, and skewed left-sided difference 4th order error.
Program for calculating 4th order error of second-order derivative using central, skewed right-sided, and skewed left-sided scheme using previously developed functions:
%calculating 4th order error of second-order derivative using central, skewed right-sided and left-sided scheme;
clear all
close all
clc
x=pi/3;
dx=linspace(pi/4,pi/40000,40);
%creating 'for' loop;
for i=1:length(dx)
central_difference_error(i)=central_difference(x,dx(i));
skewed_right_side_error(i)=skewed_right_sided(x,dx(i));
skewed_left_side_error(i)=skewed_left_sided(x,dx(i));
end
%plotting graphs for dx vs errors for central, skewed right-sided, & skewed left-sided approximations
figure(1)
plot(dx,central_difference_error,'linewidth',2)
hold on
grid on
plot(dx,skewed_right_side_error,'r','linewidth',2)
hold on
plot(dx,skewed_left_side_error,'g','linewidth',2)
xlabel('dx')
ylabel('error')
legend('Central Difference Error','Skewed Right-Sided Error','Skewed Left-Sided Error')
figure(2)
loglog(dx,central_difference_error,'linewidth',2)
hold on
grid on
loglog(dx,skewed_right_side_error,'r','linewidth',2)
hold on
loglog(dx,skewed_left_side_error,'g','linewidth',2)
xlabel('dx')
ylabel('error')
legend('Central Difference Error','Skewed Right-Sided Error','Skewed Left-Sided Error')
Output:
figure(1)
figure(2)
After analyzing the graph between ‘error’ vs. ‘dx’ for central, skewed right-sided, and skewed left-sided difference 4th order error; we can easily notice that central difference approximation produces more accurate solutions; hence produces lesser errors as compared to right-skewed and left-skewed difference schemes.
In your own words, describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot do?
Since we can see that the central differencing scheme gives us more immaculate solutions or lesser errors as compared to the skewed difference scheme. But it is not always viable to use the central differencing to evaluate solutions. Suppose, if we want to compute numerical approximations for a function at the boundary or corner node; we cannot use the central difference scheme at this particular situation because it requires data from both sides of the node or boundary. So, in this situation skewed difference method plays a major role; as in the skewed scheme data from one side can be used to compute numerical approximation at a point.
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...
Project 1 : CFD Meshing for Tesla Cyber Truck
CFD Meshing for Tesla Cyber Truck Initial Model First of all…
09 Nov 2022 05:46 PM IST
Week 10 - Simulating Combustion of Natural Gas.
COMBUSTION Combustion is defined as a chemical reaction in which a hydrocarbon reacts with an oxidant to form products, accompanied by the release of energy in the form of heat. Combustion manifests as awode domain during the design, analysis, and performance characteristics stage by being an integral part of various…
08 Nov 2022 07:38 PM IST
Week 9 - Parametric study on Gate valve.
Theory: Introduction: Gate valves are designed for fully open or fully closed service. They are installed in pipelines as isolating valves and should not be used as control or regulating valves. Operation of a gate valve is performed doing an either clockwise to close (CTC) or clockwise…
07 Nov 2022 05:07 PM IST
Week 12 - Validation studies of Symmetry BC vs Wedge BC in OpenFOAM vs Analytical H.P equation
Angles to test: θ=100 θ=250 θ=450 Expected Results Validate Hydro-dynamic length with the numerical result Validate the fully developed flow velocity profile with its analytical profile Validate maximum velocity and pressured drop for fully developed flow Post-process Shear stress and validate…
06 Nov 2022 06:53 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.