4th order approximation of second order
Derivation of fourth order approximation of the second order:
fig(a) fig(b) fig(c) fig(d)
In fig(a) and fig(b) central difference scheme equations were derived using taylor series expansion.In fig(c) and fig(d) skewed right difference and skewed left difference equations were derived using taylor series expansion and taylor\'s table method to find the values of co-efficients in the fourth order second derivative equations.
Matlab program:
function out = central_differencing_approximation(x,dx)
%analitycal function = e^x*cos(x)
%analitycal second order derivative
%f\'\'(x)=-2*(e^x)*sin(x)
analitycal_second_order_derivative = 2*(e^x)*sin(x);
%numerical derivative
%central differencing
central_differencing = (((-0.0833)*(e^(x-2*dx)*cos(x-2*dx)))+((1.333)*(e^(x-dx)*cos(x-dx)))-((2.5)*(e^x*cos(x)))+((1.333)*(e^(x+dx)*cos(x+dx)))-((0.0833)*(e^(x+2*dx)*cos(x+2*dx))))/dx^2;
%error
out = abs(central_differencing-analitycal_second_order_derivative);
------------------------------------------------------------------------------------------
function out = skewed_right_difference_approximation(x,dx)
%analitycal function = e^x*cos(x)
%analitycal second order derivative
%f\'\'(x)=-2*(e^x)*sin(x)
analitycal_second_order_derivative = 2*(e^x)*sin(x);
%numerical derrivative
%skewed right difference
skewed_right_difference = ((e^x*cos(x))-(2*(e^(x+dx)*cos(x+dx)))+(e^(x+2*dx)*cos(x+2*dx)))/dx^2
%error
out = abs(skewed_right_difference-analitycal_second_order_derivative);
----------------------------------------------------------------------------------------
function out = skewed_left_difference_approximation(x,dx)
%analitycal function = e^x*cos(x)
%analitycal second order derivative
%f\'\'(x)=-2*(e^x)*sin(x)
analitycal_second_order_derivative = 2*(e^x)*sin(x);
%numerical derivative
%skewed left difference
skewed_left_difference = (((0.1428)*(e^(x-2*dx)*cos(x-2*dx)))-((0.0408)*(e^(x-dx)*cos(x-dx)))-((0.10204)*(e^(x)*cos(x))))/dx^2;
%error
out = abs(skewed_left_difference-analitycal_second_order_derivative);
----------------------------------------------------------------------------------------
function out = forward_difference_apprx(x,dx)
%analitycal function = e^x*cos(x)
%analitycal second order derivative
%f\'\'(x)=-2*(e^x)*sin(x)
analitycal_second_order_derivative = -2*(e^x)*sin(x);
%numerical derivative
%forward_difference
forward_difference = ((e^(x+dx)*cos(x+dx))-(e^(x)*cos(x)))/dx;
%error
out = abs(analitycal_second_order_derivative-forward_difference);
----------------------------------------------------------------------------------------
function out = backward_difference_apprx(x,dx)
%analitycal function = e^x*cos(x)
%analitycal second order derivative
%f\'\'(x)=-2*(e^x)*sin(x)
analitycal_second_order_derivative = -2*(e^x)*sin(x);
%numerical derivative
%backward_difference
backward_difference = ((e^(x-dx)*cos(x-dx))-(e^(x)*cos(x)))/dx;
%error
out = abs(analitycal_second_order_derivative-backward_difference );
----------------------------------------------------------------------------------------
clear all
close all
clc
x=pi;
dx= linspace(pi/100,pi/40,50);
for i=1:length(dx);
forward_error(i)=forward_difference_apprx(x,dx(i));
backward_error(i)=backward_difference_apprx(x,dx(i));
central_difference_error(i)=central_differencing_approximation(x,dx(i));
skewed_right_error(i)=skewed_right_difference_approximation(x,dx(i));
skewed_left_error(i)=skewed_left_difference_approximation(x,dx(i));
end
figure(1)
plot(dx,central_difference_error,\'r\')
hold on
plot(dx,forward_error,\'--\')
hold on
plot(dx,backward_error,\'-o-\')
xlabel(\'dx\')
ylabel(\'error\')
legend(\'central difference error\',\'forward error\',\'backward error\')
figure(2)
plot(dx,skewed_right_error,\'g\')
hold on
plot(dx,forward_error,\'--\')
hold on
plot(dx,backward_error,\'-o-\')
xlabel(\'dx\')
ylabel(\'error\')
legend(\'skewed right error\',\'forward error\',\'backward error\')
figure(3)
plot(dx,skewed_left_error,\'b\')
hold on
plot(dx,forward_error,\'--\')
hold on
plot(dx,backward_error,\'-o-\')
xlabel(\'dx\')
ylabel(\'error\')
legend(\'skewed left error\',\'forward error\',\'backward error\')
----------------------------------------------------------------------------------------
Plots that compare absolute error with numerical second derivatives and FDS and BDS:
figure(1) figure(2) figure(3)
In figure(1), we can observe that central difference error decreases as dx increases. In figure(2), the skewed right error increases as dx increases. In figure(3), the skewed left error decreases as dx increases just like central difference. And the forward error and backward error almost remains constant when compared to the central difference error, skewed right error and skewed left error. From the above observation we can say that the error for the central difference approximation and error for the skewed left difference approximation varies in similar way, in skewed right difference approximation, error increases with dx.
Skewed scheme advantages over central difference scheme:
In skewed scheme it takes the points from either right or left side and the errors are lower compared to the central difference scheme.