Project

Taylor Table Method

Using the Taylor table method to derive the coefficients a b c d and e for skewed right side difference, skewed left side difference and central difference scheme.

Table for skewed forward difference scheme is as follows-

f(i)

f’(i)

f’’(i)

f’’’(i)

f’’’’(i)

f(i)

a

0

0

0

0

f(i+1)

b

b

b/2

b/6

b/24

f(i+2)

c

2c

2c

c.4/3

c.2/3

f(i+3)

d

3d

d.9/2

d.9/2

d.27/8

f(i+4)

e

4.e

8.e

e.32/3

e.32/3

Therefore adding all the coefficients of - f(i), f’(i), f’’’(i) and f’’’’(i) and equating them to zero

And equating coefficients of f’’(i) to 1

We get following Matrix

Table for skewed backward difference scheme is as follows-

f(i)

f’(i)

f’’(i)

f’’’(i)

f’’’’(i)

f(i)

a

0

0

0

0

f(i-1)

b

-b

b/2

-b/6

b/24

f(i-2)

c

-2c

2c

-c.4/3

c.2/3

f(i-3)

d

-3d

d.9/2

-d.9/2

d.27/8

f(i-4)

e

-4.e

8.e

-e.32/3

e.32/3

Therefore adding all the coefficients of - f(i), f’(i), f’’’(i) and f’’’’(i) and equating them to zero

And equating coefficients of f’’(i) to 1

We get following Matrix

Table for Central difference scheme is as follows

f(i)

f’(i)

f’’(i)

f’’’(i)

f’’’’(i)

f(i)

a

0

0

0

0

f(i+1)

b

b

b/2

-b/6

b/24

f(i-1)

c

-c

c/2

-c/6

c/24

f(i+2)

d

2d

2d

d.4/3

d.2/3

f(i-2)

e

-2.e

2.e

-e.4/3

e.2/3

Therefore adding all the coefficients of - f(i), f’(i), f’’’(i) and f’’’’(i) and equating them to zero

And equating coefficients of f’’(i) to 1

We get following Matrix

Now using the system of linear equations and solving the equations using below code to find coefficients of a,b,c,d and e

clear all 
close all
clc

% To find the coefficients of a,b,c,d, and e for FDS, BDS and CDS scheme


% Solving equations for FDS schemes to find coefficients
syms a1 b1 c1 d1 e1

eq1= a1+b1+c1+d1+e1 ==0;
eq2= 0+b1+2*c1+3*d1+4*e1==0;
eq3= 0+b1/2+2*c1+9/2*d1+8*e1==1;
eq4=0+b1/6+(4/3)*c1+(9/2)*d1+(32/3)*e1==0;
eq5 = 0+b1/24+(2/3)*c1+(27/8)*d1+(32/3)*e1==0;


[A1,B1] = equationsToMatrix([eq1,eq2,eq3,eq4,eq5],[a1,b1,c1,d1,e1]);

X_FDS = linsolve(A1,B1);


% Solving equations for BDS schemes to find coefficients
syms a2 b2 c2 d2 e2

eq1= a2+b2+c2+d2+e2 ==0;
eq2= 0-b2-2*c2-3*d2-4*e2==0;
eq3= 0+b2/2+2*c2+9/2*d2+8*e2==1;
eq4=0-b2/6-(4/3)*c2-(9/2)*d2-(32/3)*e2==0;
eq5 = 0+b2/24+(2/3)*c2+(27/8)*d2+(32/3)*e2==0;


[A2,B2] = equationsToMatrix([eq1,eq2,eq3,eq4,eq5],[a2,b2,c2,d2,e2]);

X_BDS = linsolve(A2,B2);

% Solving equations for CDS schemes to find coefficients
syms a3 b3 c3 d3 e3

eq1= a3+b3+c3+d3+e3 ==0;
eq2= 0+b3-c3+2*d3-2*e3==0;
eq3= 0+b3/2+c3/2+2*d3+2*e3==1;
eq4= 0+b3/6-c3/6+(4/3)*d3-(4/3)*e3==0;
eq5= 0+b3/24+c3/24+(2/3)*d3+(2/3)*e3==0;

[A3,B3] = equationsToMatrix([eq1,eq2,eq3,eq4,eq5],[a3,b3,c3,d3,e3]);

X_CDS = linsolve(A3,B3);





So now values for coefficients a b c d and e are as follows

For FDS and BDS

a =35/12
b = -26/3
c =19/2
d= -14/3
e =11/12

For CDS

a = -5/2
b = 4/3
c =4/3
d =-1/12
e =-1/12

For forward differencing scheme derivative is given by

For backward differencing scheme derivative is given by

For central differencing scheme derivative is given by

Substituting values for a, b, c, d and e in above formula following functions are generated

Following are the functions used in script

Function for exp(x)*cos(x)

function out = e_(x)

 out = exp(x)*cos(x);
end

Function for Central differencing Scheme

% Function to calculate Central differencing scheme
function cds_fourth_order = CDS(x,dx)
 
 a = -5/2;
 b=  4/3;
 c =  4/3;
 d=   -1/12;
 e = -1/12;


u=(x+dx);
v=(x-dx);
w=(x+(2*dx));
y=(x-(2*dx));   

f_i = a*e_(x);
 f_iplus1 = b*e_(u);
 f_iminus1 = c*e_(v);
 f_iplus2 = d*e_(w);
 f_iminus2 = e*e_(y);
 
 
 cds_fourth_order = ((f_i)+(f_iplus1)+(f_iminus1)+(f_iplus2)+(f_iminus2))/(dx^2);
 
end
 

Function for forward differencing scheme

function out = skewed_fourth_order_fds(x,dx)
 a = 35/12;
 b=  -26/3;
 c = 19/2;
 d= -14/3;
 e = 11/12;


 f_i = e_(x);
 f_iplus1 = e_(x+dx);
 f_iplus2 = e_(x+(2*dx));
 f_iplus3 = e_(x+(3*dx));
 f_iplus4 = e_(x+(4*dx));
 
 
 out= (a*(f_i)+(b*f_iplus1)+(c*f_iplus2)+(d*f_iplus3)+(e*f_iplus4))/(dx^2);

Function for Backward differencing scheme

function out = skewed_fourth_order_bds(x,dx)
 a = 35/12;
 b=  -26/3;
 c = 19/2;
 d= -14/3;
 e = 11/12;



 f_i = e_(x);
 f_iplus1 = e_(x-dx);
 f_iplus2 = e_(x-(2*dx));
 f_iplus3 = e_(x-(3*dx));
 f_iplus4 = e_(x-(4*dx));
 
 
 out= ((a*f_i)+(b*f_iplus1)+(c*f_iplus2)+(d*f_iplus3)+(e*f_iplus4))/(dx^2);

Script

clear all 
close all 
clc

% analytical  function = exp(x)*cos(x)

%analytical derivative of second order = -2*exp(x)*sin(x)


x = pi/2; % Current value of x

dx = linspace(0.01,0.1,10); % gridspacing


for i = 1:length(dx);

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

central_fourth_approximation(i)= CDS(x,dx(i));

Skewed_fourth_order_approximation_FDS(i) = skewed_fourth_order_fds(x,dx(i));

Skewed_fourth_order_approximation_BDS(i) = skewed_fourth_order_bds(x,dx(i));


error_cds(i) = abs(analytical_derivative-central_fourth_approximation(i));

error_fds(i) = abs(analytical_derivative-Skewed_fourth_order_approximation_FDS(i));

error_bds(i) = abs(analytical_derivative-Skewed_fourth_order_approximation_BDS(i));

end


% Plotting the Graph
figure(1)

loglog(dx,error_cds,\'marker\',\'*\',\'linewidth\',1);
hold on
loglog(dx,error_fds,\'b\',\'marker\',\'o\',\'linewidth\',1);
loglog(dx,error_bds,\'g\',\'marker\',\'s\',\'linewidth\',1);
grid on
xlabel(\'Grid size\');
ylabel(\'Error Value\');
legend(\'Error Central Differncing Scheme\',\'Error Forward Differncing Scheme\',\'Error Backward Differncing Scheme\');
title({\'Graph comparing absoulute error between Central Differencing,\', \'Forward Differncing and Backward Differncing Schemes\'});

% Saving the Graph
saveas(gca,\'taylor table comparison.jpeg\')

Plot is as follows

From above plot we can deduce that

1. As step size increases the error value increases.

2. Error for central differencing scheme is less than forward and backward differencing scheme. And there is less difference between error value for forward and backward difference scheme.

When skewed schemes are useful-

Skewed schems are useful when we have the endpoints, whereas Central Differencing Schemes cannot be used when we have endpoints.

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.