Challenge

Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method

1. CENTRAL DIFFERENCING :

Deriving the central differencing for the fourth order approximation of the second order derivative of a function using Taylor's method.

To find the central differencing we need to find the number of nodes required to evaluate the second order accurate.

Number of nodes N = P+Q-1

where,

P = order of derivative

Q = order of approximation

For the order approximation of the second order derivative, number of nodes required to derive central differencing is

N = 2+4-1 = 5.

The second order derivative is expressed as

`Deltax^2f'(x) = af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2)`

Evaluating the each term of the hypothesis using Taylor's series.

`af(i-2) = a[f(i)-2Deltax/1!f'(i) +(2Deltax)^2/2!f''(i)-(2Deltax)^3/3!f'''(i)+(2Deltax)^4/4!f''''(i)+.......`

`bf(i-1) = b[f(i)-Deltax/1!f'(i) +(Deltax)^2/2!f''(i)-(Deltax)^3/3!f'''(i)+(Deltax)^4/4!f''''(i)+......`

`cf(i) = cf(i)`

`df(i+1) = d[f(i)+Deltax/1!f'(i) +(Deltax)^2/2!f''(i)+(Deltax)^3/3!f'''(i)+(Deltax)^4/4!f''''(i)+.......`

`ef(i-2) = e[f(i)+2Deltax/1!f'(i) +(2Deltax)^2/2!f''(i)+(2Deltax)^3/3!f'''(i)+(2Deltax)^4/4!f''''(i)+.......`

Taylors table

af(i-2) a -2a 4a/2 -8a/6 16a/24
bf(i-1) b -b b/2 -b/6 b/24
cf(i) c 0 0 0 0
df(i+1) d d d/2 d/6 d/24
ef(i+2) e 2e 4e/2 8e/6 16e/24

Evaluation for second order derivative

0 0 1 0 0

With the help of the Taylor's tabel we can find the value of the coefficients by forming theequations.

  1. a+b+c+d+e = 0
  2. -2a-b+0+d+2e = 0
  3. 4a/2+b/2+0+d/2+4e/2 = 1
  4. -8a/6-b/6+0+d/6+8e/6 = 0
  5. 16a/24+b/24+0+d/24+16e/24 = 0

Command window :

On solving these equations we get the values of the coefficient and these values of the coefficient are used in the equation 1 for deriving the second order derivative for the fourth order approximation of the function for central differencing.

2. SKEWED-RIGHT SIDED DIFFERENCE :

In this method same procedure is followed

The number of nodes required,

N = P+Q

where

P = Order of derivative

Q = Order of approximation

For fourth order approximation of the second order derivative, number of nodes required to derive skewed right-sided difference is

N = 2+4 = 6.

The second order derivative is expressed as

`Deltax^2f''(x) = af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)+.....`

Evaluating the each term of the hypothesis using Taylor's series

`af(i) = af(i)`

`bf(i+1) = b[f(i)+Deltax/1!f'(i) +(Deltax)^2/2!f''(i)+(Deltax)^3/3!f'''(i)+(Deltax)^4/4!f''''(i)+.......`

`cf(i+2) = c[f(i)+2Deltax/1!f'(i) +(2Deltax)^2/2!f''(i)+(2Deltax)^3/3!f'''(i)+(2Deltax)^4/4!f''''(i)+.......`

`df(i+3) = d[f(i)-3Deltax/1!f'(i) +(3Deltax)^2/2!f''(i)+(3Deltax)^3/3!f'''(i)+(3Deltax)^4/4!f''''(i)+.......`

`ef(i+4) = e[f(i)+4Deltax/1!f'(i) +(4Deltax)^2/2!f''(i)+(4Deltax)^3/3!f'''(i)+(4Deltax)^4/4!f''''(i)+.......`

`gf(i-2) = g[f(i)-5Deltax/1!f'(i) +(5Deltax)^2/2!f''(i)+(5Deltax)^3/3!f'''(i)+(5Deltax)^4/4!f''''(i)+.......`

Taylor's table :

af(i) a 0 0 0 0 0
bf(i+1) b b b/2 b/6 b/24 b/120
cf(i+2) c 2c 4c/2 8c/6 16c/24 32c/120
df(i+3) d 3d 9d/2 27d/6 81d/24 243d/120
ef(i+4) e 4e 16e/2 64e/6 156e/24 1024e/120
gf(i+5) g 59 25e/2 125g/6 625g/24 3125g/120

Evaluation for second order derivative

0 0 1 0 0

With the help of taylors table we can find the values of the coefficient by forming the equations,

  1. a+b+c+d+e+g = 0
  2. b+2c+3d+4e+5g = 0
  3. b/2+4c/2+9d/2+16e/2+125g/2 = 1
  4. b/6+8c/6+27d/6+64e/6+125g/6 = 0
  5. b/24+16c/24+81d/24+256e/24+625g/24 = 0
  6. b/120+32c/120+243d/120+1024e/120+3125g/120 = 0

Command window :

On solving these equations we get the values of the coefficients and these values of the coefficients are used in the equation 2 for deriving the second order derivative fpr the fourth order approximation of the skewed right side differencing.

3. SKEWED LEFT-SIDE DIFFERENCE :

In this method same procedure is followed as before.

The number of nodes required

N = P+Q

Where,

P = Order of derivative

Q = Order of approximation

For fourth order approximation of the second order derivative, number of nodes required to derive skewed left-sided difference is N = 2+4 = 6.

`af(i-5) = a[f(i)-5Deltax/1!f'(i)+(5Deltax)^2/2!f''(i)-(5Deltax)^3/3!f'''(i)+(5Deltax)^4/4!f''''(i)......`

`bf(i-4) = b[f(i)-4Deltax/1!f'(i)+(4Deltax)^2/2!f''(i)-(4Deltax)^3/3!f'''(i)+(4Deltax)^4/4!f''''(i)......`

`cf(i-3) = a[f(i)-3Deltax/1!f'(i)+(3Deltax)^2/2!f''(i)-(3Deltax)^3/3!f'''(i)+(3Deltax)^4/4!f''''(i)......`

`df(i-5) = d[f(i)-2Deltax/1!f'(i)+(2Deltax)^2/2!f''(i)-(2Deltax)^3/3!f'''(i)+(2Deltax)^4/4!f''''(i)......`

`aef(i-1) = e[f(i)-Deltax/1!f'(i)+(Deltax)^2/2!f''(i)-(Deltax)^3/3!f'''(i)+(Deltax)^4/4!f''''(i)......`

`gf(i) = gf(i)`

Taylor's table :

af(i-5) a -5a 25a/2 -125a/6 625a/24 -3125a/120
bf(i-4) b -4b 16b/2 -64b/6 256b/24 -1024b/120
cf(i-3) c -3c 9c/2 -27c/6 81c/24 -243c/120
df(i-2) d -2d 4d/2 -8d/6 16d/24 -32d/120
ef(i-1) e -e e/2 -e/6 e/24 -e/120
gf(i) g 0 0 0 0 0

With the help of taylors table we can find the values of the coefficient by forming the equations,

  1. a+b+c+d+e+g = 0
  2. -5a-4b-3c-2d-e = 0
  3. 25a/6+16b/2+9c/2+4d/2+e/2 = 1
  4. -125a/6-64b/6-27c/6-8d/6-e/6 = 0
  5. 625a/24+256d/24+81c/24+16d/24+2/24 = 0
  6. -3125a/120-1024b/120-243c/120-32d/120-e/120 = 0

Command window :

On solving these equations we get the values of the coefficients and these values of the coefficient are used in the equation 3 for deriving the second order derivative for the fourth order approximation of the function for skewed lefe-sided differencing.

FUNCTION FOR CENTRAL DIFFERENCING :

function Error_central_differencing = fourth_order_central_differencing(x,dx)

% analytical derivative = exp(x)*cos(x)
% f''(X) = -2*exp(x)*sin(x)

analytic_derivative = -2*exp(x)*sin(x);

% numerical derivative
% central differencing
central_differencing = (((-1/12)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))+((4/3)*((exp(x-dx))*(cos(x-dx))))-((-5/2)*((exp(x))*(cos(x))))+((4/3)*((exp(x+dx))*(cos(x+dx))))-((-1/12)*((exp(x+(2*dx)))*(cos(x+(2*dx))))))/(dx^2);

Error_central_differencing = abs(central_differencing - analytic_derivative);

end

Function created for central differencing by using the coefficients obtained by using the Taylor's table.

FUNCTION FOR SKEWED RIGHT SIDED DIFFERENCING :

function Error_skewed_right_sided_differencing = fourth_order_skewed_right_sided_differencing(x,dx)

% analytical derivative = exp(x)*cos(x)
% f''(X) = -2*exp(x)*sin(x)

analytic_derivative = -2*exp(x)*sin(x);

% numerical derivative

skewed_right_sided_differencing = (((15/4)*((exp(x))*(cos(x))))-((-77/6)*((exp(x+dx))*(cos(x+dx))))+((107/6)*((exp(x+(2*dx)))*(cos(x+(2*dx)))))-((-13)*((exp(x+(3*dx)))*(cos(x+(3*dx)))))+((61/12)*((exp(x+(4*dx)))))-((-5/6)*((exp(x+(5*dx)))*(cos(x+(5*dx))))))/(dx^2);

% error
Error_skewed_right_sided_differencing = abs(skewed_right_sided_differencing - analytic_derivative);

end

Function created for skewed right sided differencing by using the coefficients obtained by using the Taylor's table.

FUNCTION FOR SKEWED LEFT SIDED DIFFERENCING :

function Error_skewed_left_sided_differencing = fourth_order_skewed_left_sided_differencing(x,dx)

% analytical derivative = exp(x)*cos(x)
% f''(X) = -2*exp(x)*sin(x)

analytic_derivative = -2*exp(x)*sin(x);

% numerical derivative

skewed_left_sided_differencing = (((-5/6)*((exp(x-(5*dx)))*(cos(x-(5*dx)))))+((61/12)*((exp(x-(4*dx)))*(cos(x-(4*dx)))))-((-13)*((exp(x-(3*dx)))*(cos(x-(3*dx)))))+((107/6)*((exp(x-(2*dx))))*(cos(x-(2*dx)))))-((-77/6)*((exp(x-dx))*(cos(x-dx))))+((15/4)*((exp(x))*(cos(x))))/(dx^2);

% error

Error_skewed_left_sided_differencing = abs(skewed_left_sided_differencing - analytic_derivative);

end

Function created for left sided differencing by using the coefficients obtained by using the Taylor's table .

Main program :

clear all
close all
clc

% value of x 
x = pi/3;

dx = linspace(pi/4000,pi/40,20);

% central for loop for the problem 

for i = 1:length(dx)

    central_differencing(i) = fourth_order_central_differencing(x,dx(i));

    skewed_right_sided_differencing(i) = fourth_order_skewed_right_sided_differencing(x,dx(i));

    skewed_left_sided_differencing(i) = fourth_order_skewed_left_sided_differencing(x,dx(i));

end

% plotting
figure(1)
loglog(dx,central_differencing,'Color','b')
hold on
loglog(dx,skewed_right_sided_differencing,'color','r')
hold on
loglog(dx,skewed_left_sided_differencing,'Color','g')
xlabel('Range of dx')
ylabel('Truncation error')
title('Range of dx vs truncation error')
legend('central differencing','skewed right','skewed left')

The above given program is the main programe used for calculating fourth order approximation of the second order derivative.

Three function codes are created for the main programto get the accurate results.

By using accurate results, we get the plot.

Work space :

The workspace stores the output values of the program.

PLOT :

From the above plot we can conclude that central differencing has less errors comparred to two other functions.

Because it uses the information from the sides of the stencils.

In right side differencing, information is used from one point interest and it gives less accurate results.

In left sided differencing also, information is used from one point intrest and it gives less accurate reslts.

xlabelrepresents range of dx.

ylabel represents truncation.

Why a skewed scheme is useful ?

The system which doesnot contain sufficient information on both sides of the point of interest. In such cases we cannot use central differencing scheme so skewed scheme is useful in such cases.

What can we skewed scheme do that a CD scheme cannot do ?

Central differencing cannot be employed at the boundary nodes due to unavailability of the right and left nodes at the same time. In such cases the skewed differencing scheme is used.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.