Challenge

Week 3 - Taylor table method and Matlab code

OBJECTIVE OF CHALLENGE:

To derive the central,right skewed and left skewed schemes for given function of second order derivative and fourth order approximation using taylor table also to plot the error values for a range of dx

Calculating the number of equations to be considered for taylor table

N=A+B-1; for central difference scheme

N=5

N=A+B; for both the skewed schemes

N=6

where, A=degree of the PDE

B=order of approximation

Central dfference scheme:

Taylor table:

with the coefficients in the taylor table , a system of linear equations can be drawn and are represented below in the matrix form

a3=[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];

x3=[a;b;c;d;e];

b3=[0;0;1;0;0;];

The above matrix system can be solved using matrix inversion method

a3.x3=b3

x3=a3b3

Obtained values are

x3 =

-0.083333
1.333333
-2.500000
1.333333
-0.083333

Right skewed scheme:

Taylor table:

a1=[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 64/6 625/24;0 1/120 32/120 81/40 128/15 625/24];
x1=[a;b;c;d;e;g];
b1=[0;0;1;0;0;0];

The above matrix can be solved using matrix inversion method

a1.x1=b1

x1=a1b1

obtained values are

x1 =

3.75000
-12.83333
17.83333
-13.00000
5.08333
-0.83333

Left skewed scheme:

`(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)`


Taylor table:

re -writing the taylor table in matrix form

a2=[1 1 1 1 1 1;5 4 3 2 1 0;25/2 8 9/2 2 1/2 0;125/6 64/6 27/6 8/6 1/6 0;625/24 64/6 81/24 16/24 1/24 0;625/24 128/15 81/40 32/120 1/120 0];
x2=[a;b;c;d;e;g];
b2=[0;0;1;0;0;0];

The above matrix can be solved using matrix inversion method

a2.x2=b2

x2=a2b2

obtained values are

x2 =

-0.83333
5.08333
-13.00000
17.83333
-12.83333
3.75000

code:

clear all
close all
clc

% Taylor table method and matlab code for second order derivative  and fourth order approxmation

% analytical function =(e^x)*cos(x);
x=pi/3;

dx=linspace(1,10^-1,2000);
analytical_derivative=-2*(e^x)*sin(x);


%solving taylor table equations for finding constants
% right side skewed 
a1=[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 64/6 625/24;0 1/120 32/120 81/40 128/15 625/24];
%x1=[a;b;c;d;e;g];
b1=[0;0;1;0;0;0];

x1=a1b1

% left skewed scheme
a2=[1 1 1 1 1 1;5 4 3 2 1 0;25/2 8 9/2 2 1/2 0;125/6 64/6 27/6 8/6 1/6 0;625/24 64/6 81/24 16/24 1/24 0;625/24 128/15 81/40 32/120 1/120 0];
%x2=[a;b;c;d;e;g];
b2=[0;0;1;0;0;0];

x2=a2b2

% central skewed scheme
a3=[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];
%x3=[a;b;c;d;e];
b3=[0;0;1;0;0;];

x3=a3b3


%solving anaytical function for fourth order accuracy approximation


for i=1:length(dx)
J(i)=(e.^(x-(5.*dx(i)))).*(cos(x-(5.*dx(i))));
A(i)=(e.^(x-(4.*dx(i)))).*(cos(x-(4.*dx(i))));
B(i)=(e.^(x-(3.*dx(i)))).*(cos(x-(3.*dx(i))));
C(i)=(e.^(x-(2.*dx(i)))).*(cos(x-(2.*dx(i))));
D(i)=(e.^(x-dx(i))).*(cos(x-dx(i)));
E(i)=(e.^x).*(cos(x));
F(i)=(e.^(x+dx(i))).*(cos(x+dx(i)));
G(i)=(e.^(x+(2.*dx(i)))).*(cos(x+(2.*dx(i))));
H(i)=(e.^(x+(3.*dx(i)))).*(cos(x+(3.*dx(i))));
I(i)=(e.^(x+(4.*dx(i)))).*(cos(x+(4.*dx(i))));
K(i)=(e.^(x+(5.*dx(i)))).*(cos(x+(5.*dx(i))));



%central differencing scheme
central_differencing_scheme(i)=((x3(1).*C(i))+(x3(2).*D(i))+(x3(3).*E(i))+(x3(4).*F(i))+(x3(5).*G(i)))/(dx(i).^2);
central_differencing_error(i)=abs(analytical_derivative-central_differencing_scheme(i));

%skewed right side difference scheme.
skewed_right_side_difference_scheme(i)=((x1(1).*E(i))+(x1(2).*F(i))+(x1(3).*G(i))+(x1(4).*H(i))+(x1(5).*I(i))+(x1(6).*K(i)))/(dx(i).^2);
skewed_right_side_difference_error(i)=abs(analytical_derivative-skewed_right_side_difference_scheme(i));

%skewed left side difference scheme
skewed_left_side_difference_scheme(i)=((x2(1).*J(i))+(x2(2).*A(i))+(x2(3).*B(i))+(x2(4).*C(i))+(x2(5).*D(i)+(x2(6).*E(i))))/(dx(i).^2);
skewed_left_side_difference_error(i)=abs(analytical_derivative-skewed_left_side_difference_scheme(i));

end

loglog(dx,central_differencing_error,'ob')
hold on
loglog(dx,skewed_right_side_difference_error,'^r')
hold on 
loglog(dx,skewed_left_side_difference_error,'*g')
legend('CDE','RSE','LSE')


Results and discussion:

Comparision of plots for different grid points for same range of dx

grid points =200 grid points =2000

observatoins made from the plots:

we can say that on decreasiing the value of dx, error decreases.

But both the skewed schemes shows a dip in the error for particular range of dx values where the error is lower than the dx vlues which are smaller than the previous values,this phenomena might be due to a condition ,where every equation has a optimistic solution (in our case error) for particular set of values.

Finer grid results in more accurate dx values after round off error inturn resulting in dip in error in crest region to a smaller error and coarser grid results in less accurate dx values after round off error inturn resulting in greater error values when compared with the previous conditon in the crest region.

The other obseravation which is drawn frm the plots is Central difference scheme is more efficient than the skewed schemes as it uses information from the both the adjacent grid points hence it has lower error than the other two, but skewed schemes are more efficient in calculating the extreme values as in case of 1D nozzle flow the right boundary values are extrapolated using previous grid values .

Skewed schemes are used in the implicit methods where value at 'i th 'node is calcluated usign 'i+1 th' node vaue.

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.