Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
QUESTION:
Derive the following 4th order approximations of the second-order derivative.
1. Central difference
2. Skewed right-sided difference
3. Skewed left-sided difference
After deriving these schemes, prove that your skewed schemes are fourth-order accurate i.e the thumb rule given in HINT (ii).
Once you have done this, 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.
Provide a plot that compares the absolute error between the above-mentioned schemes
In your own words, describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot?
AIM:
Derive the following 4th order approximations of the second-order derivative.
1. Central difference
2. Skewed right-sided difference
3. Skewed left-sided difference
After deriving these schemes, prove that your skewed schemes are fourth-order accurate i.e the thumb rule given in HINT (ii).
Once you have done this, 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.
Provide a plot that compares the absolute error between the above-mentioned schemes.
OBJECTIVE:
To derive the fourth order approximation of a second order derivative using central differencing scheme,skewed right difference scheme and skewed left difference scheme with the help of Taylor table and also to compare the obtained values with analytical derivative value for the given function.
PROCEDURE:
Taylor series formula is a representation of any function as an infinite sum of terms. These terms are calculated from the values of function’s derivatives at a single point. The derivative of a function f at the point x is defined as the limit of a difference quotient-

We can say the difference quotient is an approximation of the derivative f’(x) and its approximation gets better as h gets smaller. If h > 0, say h = ∆x where ∆x is a finite positive number, then it is is called the first-order or forward difference approximation of f’(x).

Similarly, if h<0, say h = -∆x, then the following expression is called as backward differencing approximation of f’(x).

By combining different Taylor series expansions, we can obtain approximations of f’(x) of various orders. Second order centred difference approximations of second order derivative –

Its easy to calculate low order approximations. For higher order approximation we can use Taylor table method. Taylor table contains coefficients of hypothesis and its derivative terms and it facilitates us to approximate function. Let’s assume we want to find the fourth order approximation of second order derivative. For it we need to assumed a point i as centre and its numerical stencil. For central differencing we have to take two forward and two backward point respective to point i. our hypothesis is going t look like as following equation -
∂2u∂x2=af(i−2)+bf(i−1)+cf(i)+df(i+1)+ef(i+2)
we have to find value of coefficients, in order to find fourth order approximation. For it first we need to expand each term using taylor series –
1.f(i−2)=a⋅f(i)–2⋅a⋅Δx⋅f’(i)1!+a⋅(2⋅Δx)2⋅f’’(i)2!–a⋅(2⋅Δx)3⋅f’’’(i)3!+a⋅(2⋅Δx)4⋅f''''(i)4!−a⋅(2⋅Δx)5⋅f'''''(i)5!+a⋅(2⋅Δx)6⋅f''''''(i)6!
2.f(i−1)=a⋅f(i)–a⋅Δx⋅f’(i)1!+a⋅(Δx)2⋅f’’(i)2!–a⋅(Δx)3⋅f’’’(i)3!+a⋅(Δx)4⋅f''''(i)4!−a⋅(Δx)5⋅f'''''(i)5!+a⋅(Δx)6⋅f''''''(i)6!
3.f(i)=c⋅f(i)
4.f(i+1)=a⋅f(i)+a⋅Δx⋅f’(i)1!+a⋅(Δx)2⋅f’’(i)2!+a⋅(Δx)3⋅f’’’(i)3!+a⋅(Δx)4⋅f''''(i)4!+a⋅(Δx)5⋅f'''''(i)5!+a⋅(Δx)6⋅f''''''(i)6!
Taylor table can be generated as following –
|
fi |
Δ xfi’ |
Δx2 fi’’ |
Δx3 fi’’’ |
Δx4 fiiv |
Δx5 fiv |
Δx6 fivi |
|
|
af(i-2) |
a |
-2a |
4a/2 |
-8a/6 |
16a/24 |
-32a/120 |
64a/720 |
|
bf(i-1) |
b |
-b |
b/2 |
-b/6 |
b/24 |
-b/120 |
b/720 |
|
cfi |
c |
0 |
0 |
0 |
0 |
0 |
0 |
|
df(i+1) |
d |
d |
d/2 |
d/6 |
d/24 |
d/120 |
d/720 |
|
ef(i+2) |
e |
2e |
4e/2 |
8e/6 |
16e/24 |
32e/120 |
64e/720 |
|
∑∑ |
0 |
0 |
1 |
0 |
0 |
? |
? |
From the table equations of coefficient can be written as –
a+b+c+d+e=0
−2a−b+0+d+2e=0
2a+b/2+0+d/2+2e=1
−8a/6−b/6+0+d/6+8e/6=0
16a/24+b/24+0+d/24+16e/24=0
solving using the MATLAB:

Taylor table for Forward differencing –
For forward differencing we have to selected four points forward to centre point those are i+1, i+2, i+3, i+4 and Taylor table can be generated in similar fashion as we did in central differencing.
|
fi |
Δ xfi’ |
Δx2 fi’’ |
Δx3 fi’’’ |
Δx4 fiiv |
Δx5 fiv |
Δx6 fivi |
|
|
af(i) |
a |
0 |
0 |
0 |
0 |
0 |
0 |
|
bf(i+1) |
b |
b |
b/2 |
b/6 |
b/24 |
b/120 |
b/720 |
|
cf(i+2) |
c |
2c |
2c |
8c/6 |
16c/24 |
32c/120 |
64c/720 |
|
df(i+3) |
d |
3d |
9d/2 |
27d/6 |
81d/24 |
243d/120 |
729d/720 |
|
ef(i+4) |
e |
4e |
16e/2 |
64e/6 |
256e/24 |
1024e/120 |
4096e/720 |
|
gf(i+5) |
g |
5g |
25g/2 |
125g/6 |
625g/24 |
3125g/120 |
15625g/720 |
|
∑∑ |
0 |
0 |
1 |
0 |
0 |
? |
? |
From the table equations of coefficient can be written as –
a+b+c+d+e+g=0
0+b+2c+3d+4e+5g=0
0+b/2+2c+9d/2+8e+25g/2=1
0+b/6+8c/6+27d/6+64e/6+125g/6=0
0+b/24+16c/24+81d/24+256e/24+625g/24=0
0+b/120+32c/120+243d/120+1024e/120+3125g/120=0
SOLVING USING THE MATLAB:

Equation for second order with fourth order equation will be –
∂^2u/∂x2=a⋅f(i)+b⋅f(i+1)+c⋅f(i+2)+d⋅f(i+3)+e⋅f(i+4)+g⋅f(i+5)
Taylor table for Backward differencing –
Points selected i, i-1, i-2, i-3, i-4
|
fi |
Δ xfi’ |
Δx2 fi’’ |
Δx3 fi’’’ |
Δx4 fiiv |
Δx5 fiv |
Δx6 fivi |
|
|
af(i) |
a |
0 |
0 |
0 |
0 |
0 |
0 |
|
bf(i-1) |
b |
-b |
b/2 |
-b/6 |
b/24 |
-b/120 |
b/720 |
|
cf(i-2) |
c |
-2c |
2c |
-8c/6 |
16c/24 |
-32c/120 |
64c/720 |
|
df(i-3) |
d |
-3d |
9d/2 |
-27d/6 |
81d/24 |
-243d/120 |
729d/720 |
|
ef(i-4) |
e |
-4e |
16e/2 |
-64e/6 |
256e/24 |
-1024e/120 |
4096e/720 |
|
gf(i-5) |
g |
-5g |
25g/2 |
-125g/6 |
625g/24 |
-3125g/120 |
15625g/720 |
|
∑∑ |
0 |
0 |
1 |
0 |
0 |
? |
? |
From the table equations of coefficient can be written as –
a+b+c+d+e+g=0
0+b+2c+3d+4e+5g=0
0+b/2+2c+9d/2+8e+25g/2=1
0+b/6+8c/6+27d/6+64e/6+125g/6=0
0+b/24+16c/24+81d/24+256e/24+625g/24=0
0+b/120+32c/120+243d/120+1024e/120+3125g/120 = 0
SOLVING USING THE MATLAB:

Equation for second order with fourth order equation will be –
∂^2u/∂x^2=a⋅f(i)+b⋅f(i−1)+c⋅f(i−2)+d⋅f(i−3)+e⋅f(i−4)+g⋅f(i−5)
Code to find second order derivative and its fourth order derivative approximation –
Central difference:-
x = pi/3;
dx = linspace(pi/4000,pi/40,20);
a = -0.0833;
b = 1.3333;
c = -2.5;
d = 1.3333;
e = -0.0833;
%-2*e^x*sinx
analytical_derivative = -2*exp(x)*sin(x);
numerical_drivative_central =(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 = abs(analytical_derivative - numerical_drivative_central);
Left sided difference-
x = pi/3;
dx = linspace(pi/4000,pi/40,20);
a = 3.75;
b = -12.8333;
c = 17.8333;
d = -13.00;
e = 5.0833;
g = -0.8333;
%-2*e^x*sinx
analytical_derivative = -2*exp(x)*sin(x);
numerical_drivative_left =(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_left = abs(analytical_derivative - numerical_drivative_left);
Right sided difference:-
x = pi/3;
dx = linspace(pi/4000,pi/40,20);
a = 3.75;
b = -12.8333;
c = 17.8333;
d = -13.00;
e = 5.0833;
g = -0.8333;
%-2*e^x*sinx
analytical_derivative = -2*exp(x)*sin(x);
numerical_drivative_right =(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);
code used to plot -
loglog(dx,error_central,dx,error_left,dx,error_right)
Code Explanation –
Three different programmes have written to compute fourth order approximation- backward, forward and central.
1. Define the variable x and dx. dx is grid size or we can say approximation distance between two nodes. dx is defined with linspace which provides a range of data.
2. Define the coefficients a, b etc, which are already computed by MATLAB.
3. Define variable analytical derivative to find second order derivative of given function.
4. Define the numerical derivative variable which is an equation. Define error, which is difference of analytic and numerical derivative.
5. loglog command is used to make log plot in command window.
RESULT:
We got plot which has forward approximation values above than central and backward approximation values below than central approximation values, it validates the theory. We infer from the graph that as values of dx is increasing the values of error also increasing.
The order of accuracy = Number of nodes in stencil - order of derivative of one sided
The order of accuracy = 6 -2 = 4
so, it proves that our skewed schemes are fourth order accurate.
Skewed approximation vs central approximation
Since the central difference approximation is superior to the forward difference approximation in terms of truncation error, it is not preferred not always. In some cases, for example convection-diffusion equations, central differencing of convective terms can lead to numerical instabilities and poor resolution of steep gradients. It is appropriate to use a forward difference at the right endpoints, a backward difference at the left endpoints and centred difference formulas for the interior points. In CFD we often have values of points on the boundary i.e. boundary conditions, so how can we start central approximation, because we don’t have knowledge of interior point. So skewed approximation has advantage here.
Leave a comment