Project

Taylor Table method Numerical Scheme for second derivative

AIM

To find the fourth order approximations for the second derivative

GOVERNING EQUATIONS

Given Function : e^xcos(x)`

OBJECTIVES OF THE PROJECT

To find a numerical scheme for the deriving second derivative of a function

BODY OF THE CONTENT

STEP 1 : Choose stencil for computing the numerical approximations

a. Central Difference Scheme (i-2, i-1,i+1,i+2)

b. Skewed Right Sided Difference (i, i-1, i-2, i-4)

c. Skewed Left Sided Difference (i, i-1, i-3, i-4)

STEP 2 : Perform Taylor series expansion of all the terms being used in the numerical stencil. The expression is used evaluated for first 7 terms.

STEP 3 : Preparing Taylor’s table for second derivative using various schemes.

i. Central Difference Scheme

Using the expressions from Step 2, Taylor table is tabulated as follows :

Solving the equation in MATLAB to get the coefficients. The coefficients are as follows:

a = -0.0833

b = 1.3333

c = -2.5

d = 1.3333

e = -0.0833

Putting the value of a, b, c, d, e in Equation VI and Equation VII we get

Expression VI : (-4/15)a + (-1/120)b + (0)c + (1/120)d + (4/15)e = 0

Expression VII : ( 4/45)a + ( 1/720)b + (0)c + (1/720)d + (4/45)e = - 0.0111

It is observed that Expression VII gives the first non-zero term in the Taylor\'s expansion of the numerical scheme.

Hence, the numerical scheme can be rewritten as :

Therefore, the numerical scheme and order of approximation is as follows :

Numerical Scheme : Central Difference Scheme

Order : Central Difference Scheme : `O(dx^4)`

ii. Skewed Right Sided Difference

Using the expressions from Step 2, Taylor table is tabulated as follows :

Solving the equation in MATLAB to get the coefficients. The coefficients are as follows:

a = 2.9167

b = -8.6667

c = 9.5000

d = -4.6667

e = 0.9167

Putting the value of a, b, c, d, e in Equation VI and Equation VII we get

Expression VI : (0)a + (1/120)b + (4/15)c + (81/40)d + (128/15)e = 0.8333

Expression VII : (0)a + (1/720)b + (4/45)c + (81/80)d + (256/48)e = 0.9963

It is observed that Expression VI gives the first non-zero term in the Taylor\'s expansion of the numerical scheme.

Hence, the numerical scheme can be rewritten as :

Therefore, the numerical scheme and order of approximation is as follows :

Numerical Scheme : Skewed Right Sided Difference

Order : Skewed Right Sided Difference :`O(dx^3)`

ii. Skewed Left Sided Difference

Using the expressions from Step 2, Taylor table is tabulated as follows :

Since, we have 5 unknowns (a ~ e). We use the first five equations, that is first five columns, that is, Eqn I to Eqn VI to compute the matrix for set of algebraic equations to be solved.

Solving the equation in MATLAB to get the coefficients. The coefficients are as follows:

a = 0.9167

b = -4.6667

c = 9.5000

d = -8.6667

e = 2.9167

Putting the value of a, b, c, d, e in Equation VI and Equation VII we get

Expression VI : (-128/15)a + (-81/40)b + (-4/15)c + (-1/120)d + (0)e = - 0.8333

Expression VII : ( 256/45)a + ( 81/40)b + ( 4/45)c + ( 1/720)d + (0)e = - 3.4028

It is observed that Expression VI gives the first non-zero term in the Taylor\'s expansion of the numerical scheme.

Hence, the numerical scheme can be rewritten as :

Therefore, the numerical scheme and order of approximation is as follows :

Numerical Scheme : Skewed Left Sided Difference

Order : Skewed Left Sided Difference :`O(dx^3)`

STEP 4 : Plotting the errors in the numerical scheme tabulated above and noting the observations.

Following points are observed that:

i. Higher Order Approximations for a derivative term tends to osciallate as it can be seen in the graph above.

ii. As we can also observe that Central Difference Scheme is already converged, whereas the skewed schemes converge at a much lower value of \'dx\'. This can be attributed to the fact, that order of approximation of Central Difference Scheme is higher, that is, 4 as compared to order of the skewed scheme, that is, 3. If the x-axis is extended in the above graph, we could observe the highe slope for central difference scheme.

iii. Another observation from the above graph is that, the skewed schemes come from opoosite directions in the Y-axis. Left skewed scheme converges from positive Y-axis, whereas, Right skewed scheme converges from negative Y-axis.

iv. The converged value of the three approximations does not seem to match with the analystical solution, because error converges to a value of 3.893 on the curve.

Question : Why are skewed schemes useful?

Answer : Skewed schemes are useful, in order to, find gradients at the boundary condition and initial conditions. This is due to the fact that we do not have grid points or time steps on either side at the boundary conditions and initial conditions respectively. Thus, to solve a governing equation using numerical stencil, a combination of schemes might be used to find the final solution.

MATLAB : DERIVATION OF COEFFIECIENTS TO DEVELOP NUMERICAL SCHEME

clc
clear all
close all

%Abbreviations
% CDS - Central Differencing Scheme
% SRD - Skewed Right sided Difference scheme
% SLD - Skewed Left sided Difference scheme

% Defing the Matrices
% Ax = b 
ACDS = [1 1 1 1 1;-2 -1 0 1 2;2 1/2 0 1/2 2;-4/3 -1/6 0 1/6 4/3;2/3 1/24 0 1/24 2/3];
ASRD = [1 1 1 1 1;0 1 2 3 4;0 1/2 2 9/2 8;0 1/6 4/3 9/2 32/3;0 1/24 2/3 27/8 32/3];
ASLD = [1 1 1 1 1;-4 -3 -2 -1 0;8 9/2 2 1/2 0;-32/3 -9/2 -4/3 -1/6 0;32/3 27/8 2/3 1/24 0];

b = [0;0;1;0;0];

% Solving for x matrix, that is, the coefficient matrix
xCDS=inv(ACDS)*b;
xSRD=inv(ASRD)*b;
xSLD=inv(ASLD)*b;

% Find the value of expression VI and expresion VII (Refer Theory)
VI_CDS=[-4/15;-1/120;0;1/120;4/15];
VII_CDS=[4/45;1/720;0;1/720;4/45];
VI_SRD=[0;1/120;4/15;81/40;128/15];
VII_SRD=[0;1/720;4/45;81/80;256/48];
VI_SLD=[-128/15;-81/40;-4/15;-1/120;0];
VII_SLD=[256/45;81/40;4/45;1/720;0];

value_VI_CDS=sum(VI_CDS.*xCDS)
value_VII_CDS=sum(VII_CDS.*xCDS)
value_VI_SRD=sum(VI_SRD.*xSRD)
value_VII_SRD=sum(VII_SRD.*xSRD)
value_VI_SLD=sum(VI_SLD.*xSLD)
value_VII_SLD=sum(VII_SLD.*xSLD)

MATLAB : GIVEN FUNCTION - `e^xcos(x)`

function out = fn(a)
out = exp(a).*(cos(a));
end

MATLAB : ERROR COMPUTAION AND ITS PLOT

clc
clear all
close all

x = pi/3;
dx = linspace(pi/40,pi/400,100);

% ANALYTICAL/EXACT SOLUTION
exact_solution = exp(x).*(cos(x)-sin(x));

% NUMERICAL SOLUTION OF FIRST DERIVATIVE
% CDS - Central Difference Scheme
CDS_approx=((-0.0833*fn(x-2*dx))+(1.3333*fn(x-dx))-(2.50*fn(x))+(1.3333*fn(x+1*dx))-(0.0833*fn(x+2*dx)))./(dx.^2)

% SRD - Skewed Right sided Difference scheme
SRD_approx = ((2.9167*fn(x))-(8.6667*fn(x+dx))+(9.5*fn(x+2*dx))-(4.6667*fn(x+3*dx))+(0.9167*fn(x+4*dx)))./(dx.^2)

% SLD - Skewed Left sided Difference scheme
SLD_approx= ((2.9167*fn(x))-(8.6667*fn(x-dx))+(9.5*fn(x-2*dx))-(4.6667*fn(x-3*dx))+(0.9167*fn(x-4*dx)))./(dx.^2)

% Preparing a row matrix the same size as size of dx
for i = 1:length(dx)
exact_sol(i)=exact_solution
end

% PLOTTING THE APPROXIMATIONS vs dx
% plot(exact_solution,\'*\')
% hold on
% plot(first_order_approx)
% plot(second_order_approx)
% plot(fourth_order_approx)

% PLOTTING THE ERRORS vs dx
error_CDS = abs(exact_sol - CDS_approx)
error_SRD = abs(exact_sol - SRD_approx)
error_SLD = abs(exact_sol - SLD_approx)

figure(1)
loglog(dx,error_CDS,\'color\',\'y\')
hold on
loglog(dx,error_SRD,\'color\',\'b\')
loglog(dx,error_SLD,\'color\',\'g\')
legend(\'Central Difference Scheme\',\'Skewed Right-sided Difference Scheme\',\'Skewed Left-sided Difference scheme\')
title(\'Error vs Mesh Grid Size(dx) - Logarithmic Plot\')
xlabel(\'Mesh Grid Size(dx)\')
ylabel(\'Error\')

% figure(2)
% plot(dx,error_CDS,\'color\',\'y\')
% hold on
% plot(dx,error_SRD,\'color\',\'b\')
% plot(dx,error_SLD,\'color\',\'g\')
% legend(\'Central Difference Scheme\',\'Skewed Right-sided Difference Scheme\',\'Skewed Left-sided Difference scheme\')
% title(\'Error vs dx - Logarithmic Plot\')

% figure(4)
% p=[error_CDS;error_SRD;error_SLD];
% bar(dx,p)
% % w1 = 0.75; 
% % bar(dx,error_CDS,w1,\'FaceColor\',[0.2 0.2 0.5])
% % w2 = .5;
% % hold on
% % bar(dx,error_SRD,w2,\'FaceColor\',[0 0.7 0.7])
% % w3 = 0.25;
% % bar(dx,error_SRD,w2,\'FaceColor\',[0.1 0.1 0.1])

% figure(1)
% plot(dx,exact_sol,\'*\',\'color\',\'r\')
% hold on
% plot(dx,CDS_approx,\'color\',\'y\')
% plot(dx,SRD_approx,\'color\',\'b\')
% plot(dx,SLD_approx,\'color\',\'g\')
% legend(\'Exact Solution\',\'Central Difference Scheme\',\'Skewed Right-sided Difference Scheme\',\'Skewed Left-sided Difference scheme\')
% title(\'Approximation vs dx - Normal Plot\')
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.