Compute higher-order approximations using skewed and symmetric stencils
Compute higher-order approximations using skewed and symmetric stencils.
Derive the following 4th order approximations of the second-order derivative.
1. Central difference
2. Skewed right-sided difference
3. Skewed left-sided difference
For central differencing
No of nodes=p+q-1=4+2-1=5
where, p= order of derivative
q=order of approximations
Similarily,
For Skewed right0sided scheme differencing
No of nodes=p+q-1=4+2=6
And,
For Skewed left-sided scheme differencing
No of nodes=p+q-1=4+2=6
Program to evaluate the second-order derivative of the analytical function exp(x)*cos(x) and compare it with the 3 numerical approximations
clear all
close all
clc
x=pi/3;
dx=linspace(pi/4,pi/4000,20);
for i=1:length(dx)
CDS_fourth_order_error(i)=cds_fourth_order_approximations(x,dx(i));
SRHS(i)=srhs_fourth_order_approximations(x,dx(i));
SLHS(i)=slhs_fourth_order_approximations(x,dx(i));
endfor
% plotting
loglog (dx,CDS_fourth_order_error,\'g\')
hold on
loglog (dx, SRHS,\'r\')
hold on
loglog (dx, SLHS,\'b\')
xlabel(\'meshgrid(dx)\')
ylabel(\'Truncation error\')
legend(\'CDS fourth order error\',\'SRHS\',\'SLHS\')
Function for CDS scheme
function out=cds_fourth_order_approximations(x,dx)
% analytical function = exp(x)*cos(x)
% anlytical second derivative
analytical_second_derivative = -2*exp(x)*sin(x);
CDS_fourth_order= ((-0.083333*exp(x-2*dx)*cos(x-2*dx))+(1.333333*exp(x-dx)*cos(x-dx))-(2.500000*exp(x)*cos(x))+(1.333333*exp(x+dx)*cos(x+dx))-(0.083333*exp(x+2*dx)*cos(x+2*dx)))/(dx^2);
out = abs(CDS_fourth_order - analytical_second_derivative);
endfunction
Function Skewed RHS
function out=srhs_fourth_order_approximations(x,dx)
% analytical function = exp(x)*cos(x)
% anlytical second derivative
analytical_second_derivative = -2*exp(x)*sin(x);
srhs_fourth_order= ((-3.03675*exp(x)*cos(x))+(2.02778*exp(x+dx)*cos(x+dx))+(2.97222*exp(x+2*dx)*cos(x+2*dx))-(3-09259*exp(x+3*dx)*cos(x+3*dx))+(1.36806*exp(x+4*dx)*cos(x+4*dx))-(0.23889*exp(x+5*dx)*cos(x+5*dx)))/(dx^2);
out = abs(srhs_fourth_order - analytical_second_derivative);
endfunction
Function Skewed LHS
function out=slhs_fourth_order_approximations(x,dx)
% analytical function = exp(x)*cos(x)
% anlytical second derivative
analytical_second_derivative = -2*exp(x)*sin(x);
slhs_fourth_order= ((-3.03675*exp(x)*cos(x))+(2.02778*exp(x-dx)*cos(x-dx))+(2.97222*exp(x-2*dx)*cos(x-2*dx))-(3-09259*exp(x-3*dx)*cos(x-3*dx))+(1.36806*exp(x-4*dx)*cos(x-4*dx))-(0.23889*exp(x-5*dx)*cos(x-5*dx)))/(dx^2);
out = abs(slhs_fourth_order - analytical_second_derivative);
endfunction
A plot that compares the absolute error between the above-mentioned schemes:
Results and conclusion from the graph-
On x-axis=Meshgrid(dx)
on y-axis=Truncation error
We can observe that the Central differencing scheme has lesser truncation error comparing to the skewed left and right-sided scheme as a function of dx. But as the spacing increases the Central differencing has increased in error, whereas both skewed schemes reduce the truncation error.
That means for the large mesh grid the skewed schemes are more accurate than central differencing.
Benefits of skewed schemes over CD scheme:
(1)In central differencing, we require another point beneath the boundary, which is outside the domain of computation and we generally have no boundary conditions for this point. So in most of cases it does not make any physical sense and it becomes inaccurate. That is why we use a polynomial approach or simply a Skewed approach.
(2) The Skewed schemes can not only apply at the boundary but also at the internal grid.
(3) Ex. For viscous flow calculation