Project

Taylor Table Method

Derivation of 4th order approximation of 2nd order derivative.

Fourth order approximations of the second order derivative using the following schemes are derived with the help of programming in MATLAB

  • Central difference scheme
  • Skewed right sided difference scheme
  • Skewed left sided difference scheme

A Matlab code is written to evaluate the second order derivative of the analytical function `exp(x)*cos(x)` and compared it with the 3 numerical approximations derived.

  • Plot which compares the absolute error between the above mentioned schemes is generated.
  • Compared with FDS and BDS approximations
  • Advantages of the skewed scheme over CD scheme is explained.

Formulation of the Taylor table for CDS.

`f\'\'(x)= (af(x-2h)+b(x-h)+cf(x)+df(x+h)+ef(x+2h))/h^2`

Formulation of the Taylor table method for right skewed scheme

`f\'\'(x)=(af(x)+bf(x+h)+cf(x+2h)+df(x+3h)+ef(x+4h)+ff(x+5h))/h^2`

Formulation of the Taylor table method for Left skewed scheme

`f\'\'(x)=(af(x)+bf(x-h)+cf(x-2h)+df(x-3h)+ef(x-4h)+ff(x-5h))/h^2`

1.Central Approximation:

`(del^2f)/(delx^2)`= 4th order accurate approximation using i-2,i-1,i,i+1 and i+2

Using Taylor series method,

`(del^2f)/(delx^2)=aunderset(i-2)f+bunderset(i-1)f + cunderset(i)f+dunderset(i+1)f+eunderset(i+2)f`

This is of the form \"AX=B\". Re-writing them in equation form

a+b+c+d+e=0 ........(2)

-2a-b+0+d+2e=0 ........(3)

2a+b/2+0+d/2+4e/6=0 ........(4)

-4a/3-b/6+0+d/6+4e/6=0 .........(5)

2a/3+b/24+0+d/24+2e/3+0 .........(6)

These values are solved using MATLAB and the values of a,b,c,d,e are

a=-0.0833 b= 1.3333 c=-2.5 d= 1.3333 e=-0.0833.

Re-writing in Tabular form, we have

2.Skewed Right approximation:

`(del^2f)/(delx^2)`= 4th order accurate approximation using i,i+1,i+2,i+3 and i+4

using Taylor series method,

`(del^2f)/(delx^2)=(aunderset(i)f+bunderset(i+1)f+cunderset(i+2)f+dunderset(i+3)f+eunderset(i+4)f)`

This is of the form \"AX=B\".Re-writing them in equation form,

a+b+c+d+e=0 .......(2)

0+b+2c+3d+4e=0 .......(3)

0+b/2+2c+9d/2+8e=1 .......(4)

0+b/6+4c/3+9d/2+32e/3=0 .......(5)

0+b/24+2c/3+27d/8+32e/3=0 .......(6)

These equations are solved using MATLAB and the values of a,b,c,d and e are

a=1.3396 b=-2.9892 c=1.9301 d=-0.2508 e=-0.0295

Re-writing them in Tabular form, we have

3.Skewed Left Approximation:

`(del^2f)/(delx^2)`=4th order accurate approximation using i-4,i-3,i-2,i-1 and i

Using Taylor Series method,

`(del^2f)/(delx^2)=aunderset(i-4)f+bunderset(i-3)f+cunderset(i-2)f+dunderset(i-1)f+eunderset(i)f`

This is of the form\"AX=B\". Re-writing in equation form,

a+b+c+d+e=0 ........(2)

-4a-3b-2c-d+0=0 ........(3)

8a+9b/2+2c+d/2+0=1 ........(4)

-32a/3-9b/2-4c/3-d/6+0=0 ........(5)

32a/3+27b/8+2c/3+d/24+0=0 ........(6)

These equations are solved using MATLAB and the values of a,b,c,d,e are

a=0.9166 b=-4.6666 c=9.5 d=-8.6666 e=2.9166

Re-writing in Tabular form, we have

1.Once after the formation of Taylor table, equations can be solved in the form of matrix.Following is the program code to derive the coefficients of the formula for the second derivative with 4th order approx for the above three schemes.

clear all
close all
clc

%Fourth order approximations are written which are solved in matrix.(dx^2)
%will be the common denominator for all the coefficients of a second
%derivative  algebraic equivalent equation. The denominator is removed to
%reduce the complexity and will be added in the final equation with the
%solved coefficients.

% skewed right schemes acquires information from the right side of points
% To obtain a fourth order approximated 2nd derivative, we need information
% from 6 right side neighbouring points
a =[1 1 1 1 1 1];
b =[0 1 2 3 4 5];
c = (1/factorial(2))*[0 1^2 2^2 3^2 4^2 5^2];
d = (1/factorial(3))*[0 1^3 2^3 3^3 4^3 5^3];
e = (1/factorial(4))*[0 1^4 2^4 3^4 4^4 5^4];
f = (1/factorial(5))*[0 1^5 2^5 3^5 4^5 5^5];

p = [a;b;c;d;e;f];
% coefficients of f\'\' are made equal to 1
q = [0;0;1;0;0;0];
w = p\\q;
coefficients_of_2nd_derivative_fourth_order_approx_skewed_right= rats(w);

% skewed left schemes acquires information from left side points
% To obtain a fourth order approximated 2nd derivative, we need information
% from 6 left side neighbouring points
g = [1 1 1 1 1 1];
h = [0 -1 -2 -3 -4 -5];
i = (1/factorial(2))*[0 (-1)^2 (-2)^2 (-3)^2 (-4)^2 (-5)^2];
j = (1/factorial(3))*[0 (-1)^3 (-2)^3 (-3)^3 (-4)^3 (-5)^3];
k = (1/factorial(4))*[0 (-1)^4 (-2)^4 (-3)^4 (-4)^4 (-5)^4];
l = (1/factorial(5))*[0 (-1)^5 (-2)^5 (-3)^5 (-4)^5 (-5)^5];

m =[g;h;i;j;k;l];
% coefficients of f\'\' are made equal to 1
n = [0;0;1;0;0;0];
t = m\\n;
coefficients_of_2nd_derivative_fourth_order_approx_skewed_left= rats(t);


% central scheme requires points equally from both the sides;
% To obtain a 4th order approximated second derivative, we need information
% from 5 equally distributed neighbouring points
a_1 = [1 1 1 1 1];
b_1 = [-2 -1 0 1  2];
c_1 = (1/factorial(2))*[(2)^2 (1) (0) (1) (2)^2];
d_1 = (1/factorial(3))*[-(2)^3 (-1) (0) (1) (2)^3];
e_1 = (1/factorial(4))*[(2)^4 (1) (0) (1) (2)^4];

f_1 =[a_1;b_1;c_1;d_1;e_1];

% coefficients of f\'\' are made equal to 1
g_1 = [0;0;1;0;0];
h_1 = f_1\\g_1;
coefficients_of_2nd_derivative_fourth_order_approx_central = rats(h_1);

% Sum of the coefficients should be zero
check_1 = w(1)+ w(2)+ w(3)+ w(4) +w(5)+ w(6);
checking_forward = rats(check_1);
check_2 = t(1) + t(2)+ t(3)+ t(4)+ t(5)+ t(6);
checking_backward = rats(check_2);
check_3 = h_1(1) + h_1(2)+ h_1(3)+ h_1(4)+ h_1(5);
checking_central = rats(check_3);

2.Program which results a plot for the absolute error between the above three schemes.

clear all
close all
clc

%f(x)=exp(x)*cos(x)
% f\'\'(x)=-2*exp(x)*sin(x)

x = pi/4;
dx = linspace(pi/1000,pi/500,100);
f = exp(x)*cos(x);
exact_second_derivative = -2*exp(x)*sin(x);

for i=1:length(dx)
    
    a(i)=(exp(x-(5*dx(i)))*cos(x-(5*dx(i))));
    b(i)=(exp(x-(4*dx(i)))*cos(x-(4*dx(i))));
    c(i)=(exp(x-(3*dx(i)))*cos(x-(3*dx(i))));
    d(i)=(exp(x-(2*dx(i)))*cos(x-(2*dx(i))));
    e(i)=(exp(x-dx(i))*cos(x-dx(i)));
    f(i)= exp(x)*cos(x);
    g(i)=(exp(x+dx(i))*cos(x+dx(i)));
    h(i)=(exp(x+(2*dx(i)))*cos(x+(2*dx(i))));
    j(i)=(exp(x+(3*dx(i)))*cos(x+(3*dx(i))));
    k(i)=(exp(x+(4*dx(i)))*cos(x+(4*dx(i))));
    l(i)=(exp(x+(5*dx(i)))*cos(x+(5*dx(i))));
    
    fourth_order_2nd_derivative_skewed_right(i) = (1/(12*(dx(i)^2)))*(45*(f(i))-154*(g(i))+214*(h(i))-156*(j(i))+61*(k(i))-10*(l(i)));
    fourth_order_2nd_derivative_skewed_left(i) = (1/(12*(dx(i)^2)))*(45*(f(i))-154*(g(i))+214*(h(i))-156*(j(i))+61*(k(i))-10*(l(i)));
    fourth_order_2nd_derivative_central(i) = (1/(12*(dx(i)^2)))*(-1*(d(i))+16*(e(i))-30*(f(i))+16*(g(i))-(h(i)));
    
    
    fourth_order_skew_right_error(i)= abs(fourth_order_2nd_derivative_skewed_right(i)-exact_second_derivative);
    fourth_order_skew_left_error(i)= abs(fourth_order_2nd_derivative_skewed_left(i)-exact_second_derivative);
    fourth_order_central_error(i)= abs(fourth_order_2nd_derivative_central(i)-exact_second_derivative);
    
end

%Error differences among the above three schemes
    
    loglog(dx, fourth_order_skew_right_error,\'Marker\',\'o\',\'linewidth\',2);
    hold on
    loglog(dx, fourth_order_skew_left_error,\'m\',\'linewidth\',2);
    hold on
    loglog(dx, fourth_order_central_error,\'r\',\'linewidth\',2);
    legend(\'fourth order skew right error\',\'fourth order skew left error\',\'fourth order central error\');
    xlabel(\'dx\');
    ylabel(\'Error\');
    
    
    

OUTPUT

This below figure depicts the variation of error between the three different 4rth order derivative schemes of approximation.

How do these errors compare with FDS and BDS scheme of approximations?

FDS and BDS both acquires information from the current point and the right and left neighbouring points respectively resulting im 1st order approx for 1st order derivative with two points information whereas central diffeerence results im 2nd order approx for 1st order derivative, with two points information.With the same amountb of information Central schemes gives more accuracy due to the reduced truncation error.

FDS and BDS has some constrain, so that the skewed schemes can result in higher order approximation. Due to the perspective of symmetry, CDS schemes are more better than skewed schemes as it gains both the sides information which enhances it\'s ability to find more accurate derivatives at a certain point.

Advantages of skewed scheme over CD scheme

Skewed difference scheme works well whatever be the number of points available on the grid. For example, if there is only node available at the left and 5 nodes on the right, and we need 4th order approx for second derivative, then at that time only skewed schemes work out well. So, if we need to compute a single or higher order derivative at a corner node, then central scheme is no longer useful and there applies the skewed scheme.

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.