Project

Higher order approximations using skewed and symmetric stencils (Taylor Table)

Objective:

=>To derive the following fourth order approximation scheme of the second order derivative using following.

  • central differencing
  • skewed right sided differencing
  • skewed left sided differencing

=> Evaluate the second order derivative of the analytial function, i.e f(x) = `e^(x)*cos(x)` and compare with above numarical approximation schemes derived erlier.

=> Using plot, compare the absolutr error with respect to above schemes.

=> Compare above mentioned schemes with forward and backward approximation schemes.

=> advantage of skewed scheme over central differencing.

Explanation:

Descretize to convert partial difference equation to algebric equation. where the higher approximation is not that easy to convert in to algebric equation and its result. which make descretization more complex. Thus Taylor table comes to simplify the PDE into assumed polynomial equation and will get numarical derivatives

Taylors expansion

`f(x+Deltax) = f(x)+f\'(x)*(Deltax)/(1!)+f\'\'(x)*(Deltax)^2/(2!)+....f^n(x)*(Deltax)^n/(n!)`

where ploynomial equation contain its coeffiecients, which number depends on grid point, it means order of approximation and its order of derivative.

and coeffiecents are unknown, so here Taylor table will hep to find out the their values by simple mathematical manipulation or matrix calculation (prefered).

Where given differencing shemes will applied using \'Taylor Table\' on fourth order approximation for second order derivative.

Central differencing

let consider 5 grid points

(x-2dx), (x-dx), x, (x+dx), (x+2dx)

polynomial equation for `(del^2f)/(delx^2)` = a*f(x-2dx)+b*f(x-dx)+c*f(x)+d*f(x+dx)+e*f(x+2dx)

Taylor table

so form of equations obtained from table
a+b+c+d+e = 0

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

4a+b+d+4e = 1*2

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

16a+b+d+16e = 0

solving above equarions using matrix calculation, results are

`((a),(b),(c),(d),(e))` = `((-1/12),(4/3),(-5/2),(4/3),(-1/12))`

on substuting above values in polynomial equation and dived by `(Deltax)^2`

we get

(-f(x-2dx)+16*f(x-dx)-30*f(x)+16*f(x+dx)-f(x-2dx))/12*(dx)^2 = `f^2(x) +0*(Deltax)^4`

since a =e, b=d sixth oerder will eliminated

where `0*(Deltax)^4` is truction error of fourth order approximation for second order derivative

so numarical derivative will be

`(del^2f)/(delx^2) approx (-f(x-2*Deltax)+16*f(x-Deltax)-30*f(x)+16*f(x+Deltax)-f(x+2*Deltax))/(12*(Deltax)^2`

Skewed right sided differencing

For fourth order approximation for second order derivative.

let assume 5 grid points on right side of point x.

x, x+dx, x+2dx, x+3dx, x+4dx

polynomial will be

`(del^2f)/(delx^2) = af(x)+bf(x+Deltax)+cf(x+2Deltax)+df(x+3Deltax)+ef(x+4Deltax)`

Taylor table

so form of equation obtained from table

a+b+c+d+e = 0

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

b+4c+9d+16e = 1*2

b+8c+27d+64e = 0

b+16c+81d+256e = 0

solving above equarions using matrix calculation, results are

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

since a = e, b = d , sixth order will be eliminated, on further dividing equation by `(Deltax)^2` will get

`(35f(x)-104f(x+Deltax)+114f(x+2Deltax)-56f(x+3Deltax)+11f(x+4Deltax))/(12(Deltax)^2 )= f^2(x)+0*(Deltax)^4`

where `0*(Deltax)^4` is trucation error so equaton no longer equal.

skewed right sided differencing numarical derivative is

`(del^2f)/(delx)approx (35f(x)-104f(x+Deltax)+114f(x+2Deltax)-56f(x+3Deltax)+11f(x+4Deltax))/(12(Deltax)^2 )`

Skewed Left side differencing

for fourth order approximation for second order derivative

Following same steps as in skewed Right side differencing, we will get numarical derivative of fourth order approximation for second order derivative will be

`(del^2f)/(delx)approx (35f(x)-104f(x-Deltax)+114f(x-2Deltax)-56f(x-3Deltax)+11f(x-4Deltax))/(12(Deltax)^2 )`

Analytical function and its derivative:

Analytical function: f(x) = `e^x*cos(x)`

and analytical second order derivative `(del^2f)/(delx^2)` = `-2*e^x*sin(x)`

Code:

Defining functions

Central difference:

function central_dif_error = central_dif(x,dx)
% analytical fun f(x) = exp(x)8cos(x)
%analytical derivative of f(x)
analytical_derivative = -2*exp(x)*sin(x);
% numarical derivative
central_dif = (-(exp(x-2*dx)*cos(x-2*dx))+16*(exp(x-dx)*cos(x-dx))-30*(exp(x)*cos(x))+16*(exp(x+dx)*cos(x+dx))-(exp(x+2*dx)*cos(x+2*dx)))/(12*(dx)^2);
central_dif_error = abs(analytical_derivative-central_dif);
end

Right side differencing

function rsd_error = rsd(x,dx)
% analytical fun f(x) = exp(x)8cos(x)
%analytical derivative of f(x)
analytical_derivative = -2*exp(x)*sin(x);
% numarical derivative
rsd = ((35*exp(x)*cos(x))-104*(exp(x+dx)*cos(x+dx))+114*(exp(x+2*dx)*cos(x+2*dx))-56*(exp(x+3*dx)*cos(x+3*dx))+11*(exp(x+4*dx)*cos(x+4*dx)))/(12*(dx)^2);
rsd_error = abs(rsd-analytical_derivative);
end

left side differencing

function lsd_error = lsd(x,dx)
% analytical fun f(x) = exp(x)8cos(x)
%analytical derivative of f(x)
analytical_derivative = -2*exp(x)*sin(x);
% numarical derivative
lsd = ((35*exp(x)*cos(x))-104*(exp(x-dx)*cos(x-dx))+114*(exp(x-2*dx)*cos(x-2*dx))-56*(exp(x-3*dx)*cos(x-3*dx))+11*(exp(x-4*dx)*cos(x-4*dx)))/(12*(dx)^2);
lsd_error = abs(lsd-analytical_derivative);
end

Main programme.

clear all
close all
clc

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

for i = 1:length(dx)
    central_dif_error(i) = central_dif(x,dx(i));
    rsd_error(i) = rsd(x,dx(i));
    lsd_error(i) = lsd(x,dx(i));
end

% plotting
% comparison of errors at dx
figure(1)
plot(dx,central_dif_error,\'color\',\'b\',\'marker\',\'o\');
hold on
plot(dx,rsd_error,\'color\',\'black\',\'marker\',\'o\');
hold on
plot(dx,lsd_error,\'color\',\'red\',\'marker\',\'o\');
xlabel(\'step size of dx\');
ylabel(\'abs errors\');
title(\'variation of errors at each scheme\');
legend(\'CDS\',\'RSD\',\'LSD\');

% using loglog to understand easily

figure(2)
loglog(dx,central_dif_error,\'g\',dx,rsd_error,\'r\',dx,lsd_error,\'black\');
grid on
xlabel(\'step size of dx\');
ylabel(\'abs errors\');
title(\'consistancy of each scheme w.r.t dx vs error\');
legend(\'CDS\',\'RSD\',\'LSD\');

Where defining x = pi/3, evalute the analytical derivative and follwing different schems mentioned above.

And defining dx, which is taken no of points and compared with eachn scheme error at each step of dx. which help us to plot the graph to easy tom understand the dx vs error of each scheme.

Results and Output:

The graph represents variation of absolute error for each scheme which mentioned above for difined function of second order derivative.

From the above graph we can understand the where grid space is decreased, skewed right side differencing absolute error reduced for second derivative. other two schemes are low when compared with absolute error. we can sayn prominantly by plotting consistancy of different schemes.

The below graph represents consistancy of each scheme with respect to dx vs absolute error.

From the Graph, central differencing scheme yield the lower absolute error when compared to two other schemes. and it is approches zero absolute error with higher rate when compared to other schemes. so we can consider central differencing best option when compared to other schemes. where left side differencing seem to be reducing the absolute error but while dx getting smaller continuosly error also increased, and sudden increase error rate at certain dx and slower while dx getting small.

Schewed Scheme:

If the bulk of grid points towards right side of reference point, it would be skewed to right side so we call it as skewed right side scheme. In the same way points taken from left side of reference point, call it as Schewed Left side differencing or scheme. selecting grid points depends on order of derivative and approximation. To understand clearly figure shown below.

Numarical Stencil:

Selecting certian grid poiints according to boundary conditions for different schemes, which group called as numarical stencil.

Where applying approximation scheme at boundars, skewed scheme will be helpful to find numarical derivarive of function. Because there are no availability of grid points other side Central difference scheme is not the best option. Centrla difference must have taken grid point both sides with respect to reference point.

Conclusion:

To apply approximation scheme at boundaries, skewed schemes are recommended option to solve order of approximation of order of derivative. so, skewed scheme has more benifit over central differencing.

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.