Project

Taylor table method and Matlab code

WHAT IS TAYLOR TABLE METHOD?

  • Taylor Table will determine the coefficients of the terms which minimizes the Taylor series error. It will also determine the Taylor series error and the order of accuracy of the method.
  • In this case, Taylor Table method is used to determine the fourth-order approximations of the second-order derivative for three different schemes. i.e.

1. Central difference.

2. Skewed right-sided difference.

3. Skewed left-sided difference.

The Analytical equation to be solved is `e^(x).cos(x)`

Therefore, the second-order derivative is `-2.e^(x).sin(x)`

  • Solving for the Central Differencing:

`(d^2f)/dx^2~= a.f(i-2)+b.f(i-1)+c.f(i)+d.f(i+1)+.e.f(i+2)`

Therefore Taylor table:

f(i) dxf'(i) dx^2f''(i) dx^3f'''(i) dx^4f^iv(i) dx^5f^v(i)
af(i-2) a -2a 4a/2 -8a/6 16a/24 -32a/120
bf(i-1) b -b b/2 -b/6 b/24 -b/120
cf(I) c 0 0 0 0 0
df(i+1) d d d/2 d/6 d/24 d/120
ef(i+2) e -2e 4e/2 8e/6 16e/24 32e/120

by forming the matrix,

A=`[ [1,1,1,1, 1], [-2, -1, 0, 1, 2] ,[2, 1/2, 0, 1/2, 2], [-8/6, -1/6, 0, 1/6, 8/6],[ 16/24, 1/24, 0 ,1/24, 16/24]]`

B=`=[[0],[0],[1],[0],[0]]`

by using Matlab, we can find the X matrix.i.e. the values of variables(a,b,c,d,e)

X= `[[-0.0833] , [1.3333 ] , [ -2.5000 ] , [1.3333] , [-0.0833]]`

Therefore the C.D equation becomes,

`(d^2f)/dx^2~= (-1/12f(i-2)+4/3f(i-1)-5/12f(i)+4/3f(i+1)+-1/12f(i+2))/(dx^2)`

  • Skewed right-sided difference.

`(d^2f)/dx^2~= a.f(i)+b.f(i+1)+c.f(i+2)+d.f(i+3)+.e.f(i+4)+g.f(i+5)`

Therefore Taylor Table:

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

by forming matrix,

A=`[[ 1 ,1 ,1 ,1 ,1, 1] ,[0 ,1 ,2 ,3 ,4, 5],[ 0 ,1/2 ,2 ,9/2 ,8 ,25/2], [0 ,1/6 ,8/6 ,27/6 ,64/6 ,125/6] ,[0 ,1/24 ,16/24 ,81/24 ,256/24 ,625/24], [0 ,1/120 ,32/120 ,243/120 ,1024/120 ,3125/120]]`

B=`[ [0],[0],[1],[0],[0],[0]]`

by using Matlab, we can find the X matrix.i.e. the values of variables(a,b,c,d,e,g)

X=`[[3.7500], [-12.8333], [17.8333], [-13.0000 ], [5.0833 ], [-0.8333]]`

Therefore the equation becomes,

`((d^2f)/dx^2)~= (15/4f(i)-77/6f(i+1)+107/6f(i+2)-13f(i+3)+61/12f(i+4)-5/6f(i+5))/(dx^2)`

  • Skewed left-sided difference.

`(d^2f)/dx^2~= a.f(i-5)+b.f(i-4)+c.f(i-3)+d.f(i-2)+.e.f(i-1)+g.f(i)`

Similarly, by performing the Taylor table method we obtain,

`(d^2f)/dx^2~=( -5/6f(i-5)+61/12f(i-4)-13f(i-3)+107/6(i-2)-77/6f(i-1)+15/4f(i))/dx^2`

To find which of these schemes are more accurate, we used the MATLAB software to evaluate the error between them.

clear all
close all
clc

x=pi/3;
dx= linspace(0.001,0.1,20);

%Analytical derivative
%analytical equation= exp(x)*cos(x)
Analytical_derivative= -2*exp(x)*sin(x);

for i=1:length(dx)
    
    central_difference(i)=central_difference_taylor_series(x,dx(i));
    forward_right_differencing(i)=forward_differencing_taylor_series(x,dx(i));
    backward_left_differencing(i)=backward_differencing_taylor_series(x,dx(i));

%To find the error between three approximations
 Central_error(i)=abs(central_difference(i)-Analytical_derivative);
 Right_skewed_error(i)=abs(forward_right_differencing(i)-Analytical_derivative);
 Left_skewed_error(i)=abs(backward_left_differencing(i)-Analytical_derivative);
end

%Plotting
figure(1)
loglog(dx, Central_error,'r','linewidth',1);
hold on
loglog(dx, Right_skewed_error,'b','linewidth',1);
hold on
loglog(dx, Left_skewed_error,'g','linewidth',1);
legend('Central difference','Skewed right-sided difference','Skewed left-sided difference');
xlabel('Grid Size');
ylabel('Absolute error');
title('absolute error between the all schemes');
saveas(gca,'absolute error between the all schemes.jpg');

Functions codes used for determining the Central difference, Right Skewed Scheme and Left Skewed scheme is listed down below. The derived equation of schemes is used to find the error concerning the analytical derivative.

%CENTRAL DIFFERENCE
function central_difference= central_difference_taylor_series(x,dx)
a=-1/12;
b=4/3;
c=-5/2;
d=4/3;
e=-1/12;
f_i_minus_2 = (exp(x-(2*dx))*cos(x-(2*dx)));
f_i_minus_1 = (exp(x-dx)*cos(x-dx));
f_i= (exp(x)*cos(x));
f_i_plus_1 = (exp(x+dx)*cos(x+dx));
f_i_plus_2 = (exp(x+(2*dx))*cos(x+(2*dx)));

central_difference= ((a*(f_i_minus_2))+(b*(f_i_minus_1))+(c*(f_i))+(d*(f_i_plus_1))+(e*(f_i_plus_2)))/(dx^2);
end


%RIGHT SCKEWED SCHEME
function forward_right_differencing= forward_differencing_taylor_series(x,dx)
a= 15/4;
b=-77/6;
c=107/6;
d=-13;
e=61/12;
g=-5/6;
f_i=(exp(x)*cos(x));
f_i_plus_1=(exp(x+dx)*cos(x+dx));
f_i_plus_2= (exp(x+(2*dx))*cos(x+(2*dx)));
f_i_plus_3= (exp(x+(3*dx))*cos(x+(3*dx)));
f_i_plus_4= (exp(x+(4*dx))*cos(x+(4*dx)));
f_i_plus_5= (exp(x+(5*dx))*cos(x+(5*dx)));

forward_right_differencing= ((a*(f_i))+(b*(f_i_plus_1))+(c*(f_i_plus_2))+(d*(f_i_plus_3))+(e*(f_i_plus_4))+(g*(f_i_plus_5)))/(dx^2);
end


%LEFT SKEWED SCHEME
function left_differencing= backward_differencing_taylor_series(x,dx)
a=-5/6;
b=61/12;
c=-13;
d=107/6;
e=-77/6;
g=15/4;
f_i_minus_5= (exp(x-(5*dx))*cos(x-(5*dx)));
f_i_minus_4= (exp(x-(4*dx))*cos(x-(4*dx)));
f_i_minus_3= (exp(x-(3*dx))*cos(x-(3*dx)));
f_i_minus_2= (exp(x-(2*dx))*cos(x-(2*dx)));
f_i_minus_1= (exp(x-dx)*cos(x-dx));
f_i= (exp(x)*cos(x));

left_differencing = ((a*(f_i_minus_5))+(b*(f_i_minus_4))+(c*(f_i_minus_3))+(d*(f_i_minus_2))+(e*(f_i_minus_1))+(g*(f_i)))/(dx^2);

end

OUTPUT:

As seen from the picture, the central difference schemes appear to be more appropriate scheme as the error for it is to small compared to the Right and Left skewed scheme. This accuracy can be due to the nature of information collection in Central scheme as it collects data from both rights and left side rather than just one side. Also, the error starts to increase.i.e it changes the slope of its line as the grid(dx) starts to decrease.

WHY CAN BE A SKEWED SCHEME USEFUL?
Skewed schemes can be useful in any kind of node availability, as the scheme uses the corners of both sides considering right and left the scheme. Whereas the Central differencing scheme cannot use the corner nodes and it may get neglected while simulation/analysis.

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.