Project

Taylor Table Method and Matlab Code

1) Central Difference

`frac{del^2f}{delx^2}` ~= `af_(i-2) + bf_(i-1) +cf_i +df_(i+1) +ef_(i+2)`

In the central difference we solve the 2nd order derivative using taylor series method. we take (i-2, i-1, i, i+1, i+2) itterations to create a taylor table for simplifying our solution.

* Write the 2nd order derivative in tabular form:.

f(i)

f ’(i)

f ’’(i)

f ’’’(i)

f ’’’’(i)

`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

(16e)/24

`ef_(i+2)`

e

-2e

(4e)/2

(8e)/6

0

sum 0 0 1 0 0

`sum(af_(i-2)+bf_(i-1)+cf_(i)+df_(i+1)+ef_(i+2))`

written in the form of equations and solving the matrix

a+b+c+d+e = 0

-2a -b+0+d+2e = 0

2a+b/2+0+d/2+2e =1

-4a/3 -b/6+0+d/6+4e/6 =0

2a/3+b/24+0+d/24+2e/3 = 0

Now we have five unknowns (a,b,c,d,e) and also have five equations. To find out the values of these five unknowns we write a matlab code and get the value.

simplify this table using [A][X] = [B]

a = -0.0833

b = 1.333

c = -2.500

d = 1.3333

e = -0.083

Now we have the values of all five unknowns, put these values in equation(1)

`frac{del^2u}{delx^2}=frac{-0.08333 f_(i-2) +1.3333f_(i-1) - 2.5f_i + 1.333f_(i+1) - 0.0833 f_(i+2)}{delx^2}`

we consider LHS = RHS for this problem and neglecting the higher order than (i+2) and lower than (i-2) terms. so we get a approximation.

SKEWED LEFT SIDE SCHEME

`frac{del^2f}{delx^2}` ~= `af_(i-5) + bf_(i-4) +cf_(i-3) +df_(i-2) +ef_(i-1))+gf_(i)`

In the skewd left side scheme we solve the 2nd order derivative using taylor series method. we take (i-5, i-4, i-3, i-2, i-1, i) itterations to create a taylor table for simplifying our solution.

* Write the 2nd order derivative in tabular form:.

f(i)

f’(i)

F’’(i)

F’’’(i)

F’’’’(i)

F’’’’’(i)

af_(i-5)

a

-5a

25a/2

-125a/6

625a/24

-3125a/12

bf_(i-4)

b

-4b

16b/2

-64b/6

256b/24

-1024b/12

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

-1e/6

1e/24

-1e/120

gf(i)

g

0

0

0

0

0

sum 0 0 1 0 0 0

`sum(af_(i-5)+bf_(i-4)+cf_(i-3)+df_(i-2)+ef_(i-1)+gf_(i)`

written in the form of equations and solving the matrix

a+b+c+d+e+g = 0

-5a -4b-3c-2d-1e+0 = 0

25a/2+16b/2+9c/2+4d/2+e/2+0 =1

-125a/6-64b/6-27c/6-8d/6-1e/6+0=0

625/24a+256b/24+81/24c+16/24d+1/24e+0=0

-3125a/12-1024b/12-243c/120-32d/120-e/120+0=0

Now we have six unknowns (a,b,c,d,e,g) and also have six equations. To find out the values of these six unknowns we write a matlab code and get the value.

simplify this table using [A][X] = [B]

a = -0.8333

b = 5.0833

c = -13

d = 17.8333

e = -12.8333

g = 3.75

Now we have the values of all six unknowns, put these values in equation(1)

`frac{del^2u}{delx^2}=frac{-0.8333 f_(i-5) +5.0833f_(i-4) - 13f_(i-3) + 17.8333f_(i-2) - 12.8333 f_(i-1)+3.75f_(i)}{delx^2}`

*Skewed right side scheme

`frac{del^2f}{delx^2}` ~= `af_(i) + bf_(i+2) +cf_(i+3) +df_(i+4) +ef_(i+5))+gf_(i)`

In the skewd left side scheme we solve the 2nd order derivative using taylor series method. we take (i, i+1, i+2, i+3, i+4, i+5) itterations to create a taylor table for simplifying our solution.

* Write the 2nd order derivative in tabular form:.

F(i)

F’(i)

F’’(i)

F’’’(i)

F’’’’(i)

F’’’’’(i)

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

256e/24

1024e/120

gf(i+5)

g

5g

25g/2

125g/6

625g/24

3125g/120


sum 0 0 1 0 0 0

`sum(af_(i)+bf_(i+1)+cf_(i+2)+df_(i+3)+ef_(i+4)+gf_(i+5)`

written in the form of equations and solving the matrix

a+b+c+d+e+g = 0

0+b+2c+3d+4e+5g+= 0

0+b/2+4b/2+9b/2+16b/2+25b/2 =1

0+b/6+8c/6+27d/6+64e/6+125g/6=0

0+b/24+16c/24+81d/24+256e/24+625g/24=0

0+b/120+32c/120+243d/120+1024e/120+3125g/120=0

Now we have six unknowns (a,b,c,d,e,g) and also have six equations. To find out the values of these six unknowns we write a matlab code and get the value.

simplify this table using [A][X] = [B]

a = 3.75

b = -12.8333

c = 17.8333

d = -13

e = 5.0833

g = -0.8333

Now we have the values of all six unknowns, put these values in equation(1)

`frac{del^2u}{delx^2}=frac{3.75 f_(i) -12.8333f_(i+1) +17.833f_(i+2) -13f_(i+3) + 5.0833 f_(i+4)-0.8333f_(i)}{delx^2}`

* main program for 2nd order derivative

clear all
close all
clc

% Define Inputs 
x = pi/3;
dx = linspace(pi/40,pi/4000,50);

% Error calculation of fourth order approximation of second derivative 
% Using CDE,SRSDE,SLSDE calculate the error 
for i = 1:length(dx)
analytical_derivative = -(2*exp(x)*sin(x));
central_difference_error(i) = central_approximation(x,dx(i));
skewed_right_side_difference_error(i)= skewed_right_side_approximation(x,dx(i));
skewed_left_side_difference_error(i)= skewed_left_side_approximation(x,dx(i));

end

% Ploting the graph to compare the error
loglog(dx,central_difference_error,\'color\',\'r\')
hold on 
loglog(dx,skewed_right_side_difference_error,\'color\',\'b\')
hold on
loglog(dx,skewed_left_side_difference_error,\'color\',\'g\')
legend(\'central difference error\',\'skewed right side difference\',\'skewed left side difference\')
xlabel(\'dx\')
ylabel(\'error\')

* Function program for 2nd order derivative for fourth-order approximation for central approximation

function solution = central_approximation(x,dx);
% Analytical function 
%f(x) = exp(x)*cos(x)
% f\'\'(x) = -(2*exp(x)*sin(x));

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

% central_difference =(-0.0833*f(x-2*dx)+1.3333*f(x-dx)-2.5*f(x)+1.3333*f(x+dx)-0.0833*f(x+2*dx))/(dx)^2
% Fourth order approximation of second order derivative using central difference 

central_difference =(-0.0833*exp(x-2*dx)*cos(x-2*dx)+1.3333*exp(x-dx)*cos(x-dx)-2.5*exp(x)*cos(x)+1.3333*exp(x+dx)*cos(x+dx)-0.0833*exp(x+2*dx)*cos(x+2*dx))/(dx)^2;

solution = abs(analytical_derivative - central_difference);
end 

* Function program for 2nd order derivative for fourth-order approximation for skewed left side approximation

function solution = skewed_left_side_approximation(x,dx);
 % Analytical function   
 %f(x) = exp(x)*cos(x)
 % seccond order derivative
 % f\'\'(x) = -(2*exp(x)*sin(x))

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

% central_difference =(-0.8333*f(x-5*dx)+5.0833*f(x-4*dx)-13*f(x-3*dx)+17.8333*f(x-2*dx)-12.833*f(x-dx)+3.75*(x))/(dx)^2
% Fourth order approximation of second order derivative using central difference 

skewed_left_side_difference =(-0.8333*exp(x-5*dx)*cos(x-5*dx)+5.0833*exp(x-4*dx)*cos(x-4*dx)-13*exp(x-3*dx)*cos(x-3*dx)+17.8333*exp(x-2*dx)*cos(x-2*dx)-12.8333*exp(x-dx)*cos(x-dx)+3.75*exp(x)*cos(x))/(dx)^2;

solution = abs(analytical_derivative - skewed_left_side_difference);
end 

* Function program for 2nd order derivative for fourth-order approximation for skewed right side approximation

function solution = skewed_right_side_approximation(x,dx);
 % Analytical function 
 %f(x) = exp(x)*cos(x)
 % seccond order derivative
 % f\'\'(x) = -(2*exp(x)*sin(x))

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

% central_difference =(3.75*f(x)-12.3333*f(x+dx)+17.8333*f(x+2*dx)-13*f(x+3*dx)+5.0833*f(x+4*dx))-0.8333*f(x+5*dx))/(dx)^2
% Fourth order approximation of second order derivative using central difference 

skewed_right_side_difference =(3.75*exp(x)*cos(x)-12.8333*exp(x+dx)*cos(x+dx)+17.8333*exp(x+2*dx)*cos(x+2*dx)-13*exp(x+3*dx)*cos(x+3*dx)+5.0833*exp(x+4*dx)*cos(x+4*dx)-0.8333*exp(x+5*dx)*cos(x+5*dx))/(dx)^2;

solution = abs(analytical_derivative - skewed_right_side_difference);
end 

*Graph

*Result

-we plot the graph taking the central approximation(five variable), skewed right side approximation (six variable), a skewed left side approximation (six variable).

- As we can see in the graph that the error in skewed right side differences maximum when the value of dx is greater but when the value of dx decreases, the error also decreases and come to a constant value.

- The error in skewed left side differences maximum when the value of dx is greater but when the value of dx decreases and after some value of dx it again increases and comes to a constant value.

- The error in the central difference is approximately constant at every value of dx we choose.

The skewed scheme is useful, why?

we can see that in CDS we require the values of forwarding and backward points and compute it at the same time so the effective points are not considered which are located in corners. whereas in a skewed scheme we can easily calculate the variable at the corners (either for the right or left scheme)

Another reason for using the skewed scheme is that when we using the information available only flows in one direction (fluid flow, wind flow...) so CDS is not the best option that time because it requires both side information, so a skewed scheme is used for that kind of problem which can define it easily.

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.