Taylor s table method and matlab code

Taylor’s table method is used to derive the fourth order accurate approximation of second order derivative of a function, for three different scheme (Central difference scheme, skewed right sided difference scheme, skewed left sided difference scheme).

 

4th order approximation of second order derivative

  1. Central difference scheme:-

To derive for an error of order 4, 2nd order derivative can be approximated as:-

`(∂^2 f)/(∂x^2) ≅f'' (x)+∆x^4 f^6(x)(CONSTANT)=(a*f(i-2)+b*f(i-1)+c*f(i)+d*f(i+1)+e*f(i+2))/`

Making the coefficient of second order derivative of x as 1 the equation becomes:-

`(∂^2 f)/(∂x^2) ≅f'' (x)+∆x^4 f^6(x)(CONSTANT)=(a*f(i-2)+b*f(i-1)+c*f(i)+d*f(i+1)+e*f(i+2))/(∆x^2)`

Thus the  coefficient of 2nd order derivative of x is 1 and while that of other derivatives is 0 and 6th order derivative is an unknown finite term(which is considered as the error term).

Thus ,in error term the power of delta(x) is 4. This confirms that the approximation is of order 4.

Taylor’s table for the central difference scheme of fourth order approximation of second order derivative:-

 

             
 

a

-2a

4a/2

-8a/6

16a/24

-32a/120

64a/720

 

b

-b

b/2

-b/6

b/24

-b/120

b/720

 

c

0

0

0

0

0

0

 

d

d

d/2

d/6

d/24

d/120

d/720

 

e

2e

4e/2

8e/6

16e/24

32a/120

64e/720

coefficient

0

0

1

0

0

0

-

 

So now we get some equations,

a+b+c+d+e=0…….(1) ;  -2a-b+d+2e=0 ……….(2);   4a+b+d+4e=2 ………(3);  -8a-b+d+8e=0 …………(4)

16a+b+d+16e=0 ……….(5).

 

Solving the equation we get the coefficient of the each term and final equation is as follows:-

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

`(∂^2 f)/(∂x^2) ≅f'' (x)+∆x^4 f^6 (x)(CONSTANT)=(-f(i-2)+16*f(i-1)-30*f(i)+16*f(i+1)-f(i+2))/(12*∆x^2 )`

 

  1. Skewed right sided difference scheme:-

To derive for an order of 4, 2nd order derivative can be approximated as :-

`(∂^2 f)/(∂x^2) ≅∆x^2 f''(x)+∆x^6 f^6(x)(CONSTANT)=(a*f(i)+b*f(i+1)+c*f(i+2)+d*f(i+3)+e*f(i+4)+g*f(i+5))`

Making the coefficient of 2nd derivative as 1,the equation becomes –

`(∂^2 f)/(∂x^2) ≅∆x^2 f''(x)+∆x^6 f^6(x)(CONSTANT)=(a*f(i)+b*f(i+1)+c*f(i+2)+d*f(i+3)+e*f(i+4)+g*f(i+5))/(∆x^2)`

The coefficient of 2nd derivative is 1 while that of other derivatives 0 and of 6th derivative of  is unknown finite term (which is considered to be the error term).

Thus ,in error term the power of delta(x) is 4. This confirms that the approximation is of order 4.

Taylor’s table for the skewed right sided difference scheme of 4th order approximation of 2nd order derivative:-

 

             
 

a

0

0

0

0

0

0

 

b

b

b/2

b/6

b/24

b/120

b/720

 

c

2c

4c/2

8c/6

16c/24

32c/120

64c/720

 

d

3d

9d/2

27d/6

81d/24

243d/120

729/720

 

e

4e

16e/2

64e/6

256e/24

1024e/120

4096e/720

 

g

5g

25g/2

125g/6

625g/24

3125g/120

15625g/720

coefficient

0

0

1

0

0

0

-

 

So now we get some equations,

a+b+c+d+e+g=0…….(1); b+2c+3d+4e+5g=0 ……….(2); b+4c+9d+16e+25g=2 ………(3);  b+8c+27d+64e+125g=0 …………(4);  b+16c+81d+256e+625g=0 ……….(5); b+32c+243d+1024e+3125g…………….(6).

 

Solving the equation we get the coefficient of the each term and final equation is as follows:-

a=15/4; b=-77/6; c=107/6; d=-13; e=61/12; g=-5/6

`(∂^2 f)/(∂x^2) ≅f'' (x)+∆x^4 f^6 (x)(CONSTANT)=(45*f(i)-154*f(i+1)+214*f(i+2)-156*f(i+3)+61*f(i+4)-10*f(i+5))/(12*∆x^2 )`

 

  1. Skewed left sided difference scheme:-

To derive for an order of 4, 2nd order derivative can be approximated as :-

`(∂^2 f)/(∂x^2) ≅∆x^2 f^'' (x)+∆x^6 f^6 (x)(CONSTANT)=a*f(i)+b*f(i-1)+c*f(i-2)+d*f(i-3)+e*f(i-4)+g*f(i-5)`

Making the coefficient of 2nd derivative as 1,the equation becomes –

`(∂^2 f)/(∂x^2) ≅f''(x)+∆x^4 f^6 (x)(CONSTANT)=(af(i)+bf(i-1)+cf(i-2)+df(i-3)+ef(i-4)+gf(i-5))/(∆x)^2`

The coefficient of 2nd derivative is 1 while that of other derivatives 0 and of 6th derivative of  is unknown finite term (which is considered to be the error term).

Thus ,in error term the power of delta(x) is 4. This confirms that the approximation is of order 4.

Taylor’s table for the skewed right sided difference scheme of 4th order approximation of 2nd order derivative:-

 

             
 

a

0

0

0

0

0

0

 

b

-b

b/2

-b/6

b/24

-b/120

b/720

 

c

-2c

4c/2

-8c/6

16c/24

-32c/120

64c/720

 

d

-3d

9d/2

-27d/6

81d/24

-243d/120

729/720

 

e

-4e

16e/2

-64e/6

256e/24

-1024e/120

4096e/720

 

g

-5g

25g/2

-125g/6

625g/24

-3125g/120

15625g/720

coefficient

0

0

1

0

0

0

-

 

So now we get some equations,

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

 

Solving the equation we can get the coefficient of the each term and final equation is as follows:-

a=15/4; b=-77/6; c=107/6; d=-13; e=61/12; g=-5/6

`(∂^2 f)/(∂x^2) ≅f''(x)+∆x^4 f^6 (x)(CONSTANT)=(45*f(i)-154*f(i+1)+214*f(i+2)-156f(i+3)+61f(i+4)-10f(i+5))/(12*〖∆x〗^2 )`

 

Coefficient of above equations were find out using matlab code,so here are the matlab codes to determine the coefficients in different schemes.

1.central difference scheme code:-

%%solving equations for central difference scheme
clear all
close all 
clc

syms a b c d e 

%equations for central difference scheme
eqn_1= a+b+c+d+e==0;
eqn_2= -2*a-b+d+2*e==0;
eqn_3= 4*a+b+d+4*e==2;
eqn_4= -8*a-b+d+8*e==0; 
eqn_5= 16*a+b+d+16*e==0;

eqn=[eqn_1 eqn_2 eqn_3 eqn_4 eqn_5];

S=solve(eqn)

coef_a= S.a
coef_b= S.b
coef_c= S.c
coef_d= S.d
coef_e= S.e

2. skewed right handed difference scheme code

%%solving equations for skewed right sided difference scheme
clear all
close all 
clc

syms a b c d e g

%equations for skewed right sided difference scheme
eqn_1= a+b+c+d+e+g==0;
eqn_2= b+2*c+3*d+4*e+5*g==0;
eqn_3= b+4*c+9*d+16*e+25*g==2;
eqn_4= b+8*c+27*d+64*e+125*g==0; 
eqn_5= b+16*c+81*d+256*e+625*g==0;
eqn_6= b+32*c+243*d+1024*e+3125*g==0;

eqn=[eqn_1 eqn_2 eqn_3 eqn_4 eqn_5 eqn_6];

S=solve(eqn)

coef_a= S.a
coef_b= S.b
coef_c= S.c
coef_d= S.d
coef_e= S.e
coef_g= S.g

3. skewed left sided difference scheme

%%solving equations for skewed left sided difference scheme
clear all
close all 
clc

syms a b c d e g

%equations for skewed left sided difference scheme
eqn_1= a+b+c+d+e+g==0;
eqn_2= -(b+2*c+3*d+4*e+5*g)==0;
eqn_3= b+4*c+9*d+16*e+25*g==2;
eqn_4= -b-8*c-27*d-64*e-125*g==0; 
eqn_5= b+16*c+81*d+256*e+625*g==0;
eqn_6= -b-32*c-243*d-1024*e-3125*g==0;

eqn=[eqn_1 eqn_2 eqn_3 eqn_4 eqn_5 eqn_6];

S=solve(eqn);

coef_a= S.a
coef_b= S.b
coef_c= S.c
coef_d= S.d
coef_e= S.e
coef_g= S.g

The main program for calculate the errors in approximations using different  methods:-

%programe to compare the errors obtained by different approximation schemes
clear all 
close all 
clc

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

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

x=pi/3;
dx=linspace(pi/4,pi/40000,200);

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

for i=1:length(dx)

    [central_diff(i),skewed_right_diff(i),skewed_left_diff(i),central_error(i),skewed_right_error(i),skewed_left_error(i)]=taylor_table_scheme(x,dx(i),analytical_derivative);

end


figure(1)
loglog(dx,central_error,'r')
hold on
loglog(dx,skewed_right_error,'b')
hold on
loglog(dx,skewed_left_error,'g')
xlabel('log(dx)')
ylabel('log(error)')
legend('central difference scheme','skewed right difference scheme','skewed left difference','location','best')
title('comparision of errors for 4th order approximations for a 2nd order derivative using diff. approximation schemes')




figure(2)
plot(dx,central_error,'r')
hold on
plot(dx,skewed_right_error,'b')
hold on
plot(dx,skewed_left_error,'g')
xlabel('dx')
ylabel('error')
legend('central difference scheme','skewed right difference scheme','skewed left difference','location','best')
title('comparision of errors for 4th order approximations for a 2nd order derivative using diff. approximation schemes')

 

function programe that are used in this calculation:-

function [central_diff,skewed_right_diff,skewed_left_diff,central_error,skewed_right_error,skewed_left_error]=taylor_table_scheme(x,dx,analytical_derivative)

%numerical derivative
%central difference scheme
central_diff=((-exp_x(x-2.*dx))+(16*exp_x(x-dx))-(30*exp_x(x))+(16*exp_x(x+dx))-(exp_x(x+2.*dx)))./(12*(dx.^2));

%skewed right sided difference scheme
skewed_right_diff=((45*exp_x(x))-(154*exp_x(x+dx))+(214*exp_x(x+2.*dx))-(156*exp_x(x+3.*dx))+(61*exp_x(x+4.*dx))-(10*exp_x(x+5.*dx)))./(12*(dx.^2));

%skewed left sided difference scheme
skewed_left_diff=((45*exp_x(x))-(154*exp_x(x-dx))+(214*exp_x(x-2.*dx))-(156*exp_x(x-3.*dx))+(61*exp_x(x-4.*dx))-(10*exp_x(x-5.*dx)))./(12*(dx.^2));

%errors of numerical discritization
central_error=abs(central_diff-analytical_derivative);
skewed_right_error=abs(skewed_right_diff-analytical_derivative);
skewed_left_error=abs(skewed_left_diff-analytical_derivative);
end
function out = exp_x(x,dx)

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

end

 

output :-

 

error approximation curve 

error curve

 

loglog curve for error approximation

loglog curve for error approximation

 

conclusion:-

1. As seen from the figures the error of the central difference method is very less compared to the skewed methods. also because of its faster convergence rates CDS preffered over skewed methods. 

2. Skewed right and left difference methods almost gives the same results in terms of error for a small value of time step.

3. CDS can not be employed at the boundary nodes due to the unavailability of right or eft nodes at the same time. In succh cases the forward and backward differencing schemes are used.


Projects by Saurabh kumar sharma

Explore Tutorial No 1- SI final Introduction:- A spark ignition IC engine model take for my case study is single cylinder model. It is port injected and fuel and air enters in to the combustion chamber as homogenious mixture. This model of our engine runs at 1800 rpm Read more

  Assignment 1: Understanding GT Power   1. Introduction:- GT Suite is multiphysics CAE system simulation software. The foundation of GT suite is a versatile multi-physics plateform for constructing models of general systems based on many underlying Read more

Gearbox Sloshing effect The objective is to perform gear sloshing simulation on ansys fluent for two different gearboxes with different clearance. The User defined function is used which provides the angular velocity of 200rpm. Four simulations were performed:- Case Read more

  Challenge on Combustion Objective:- Perform a combustion simulation on the combuster model and plot the variation of the mass fraction of the different species in the simulation using line probes at different locations of the combuster. You need to plot Read more

 

Cyclone Separator Challenge

 

Objective:-

We have to perform an analysis on the cyclone seperator model for  different number of inectioned particles.

1. The four imperical models use Read more

  Gate Valve Parametric Study A gate valve, also known as a sluice valve, is a valve that opens by lifting a barrier(gate) out of the path of the fluid.Gate valves are used to shut off the flow of liquids rather than for flow regulation. Gate valve require Read more

Conjugate Heat Transfer Analysis on a graphics card. Description of a conjugate heat transfer analysis:- Conjugate heat transfer represents the combination of heat transfer in liquids and solids simulteneously. The mode of heat transfer in solids is conduction and con Read more

    Rayleigh Taylor Instability Challenge SOLUTION-1:- Models used for Rayleigh-Taylor instability:- Early-time growth Potential flow Buoyancy-drag balance Energy budget   1. Early-time growth:- It was noted in the taylor (1950) that t Read more

              Exhaust Port Challenge SOLUTION1:- Why and Where a CHT analysis is used? Conjugate Heat Transfer analysis:- Conjugate heat transfer analysis is generally used when there is a teperature variation during heating and co Read more

              Ahmed Body Challenge  SOLUTION1: Ahmed body:- The Ahmed body was originally described By S.R. Ahmed in 1984. Ahmed body is a simplified car body. The shape provides a  model to study geometric effects Read more


Loading...

The End