Project

Comparison of different numerical schemes for second order of fourth approximation

To derive the second order derivative of fourth approximation formulae for central, forward and backward difference schemes we use taylor\'s table.

It is nothing but writing the taylor series common term coefficients in a table. It\'ll help us to make this complex procedure easier.

After getting the values of coefficients we use them in respective scheme, because every scheme will have their own coefficient values.

After getting those values, we start to substitute them in the hypothesis function and we\'ll get the values of the function we need.

clear all
close all
clc
x=pi/3;
% function f(x)=exp(x)*cos(x);
analytical=-2*exp(x)*cos(x);
dx=linspace(pi/40,pi/4000,20);
for i=1:length(dx);
%skewed right sided difference
SRSD(i)=([3.79*exp(x)*cos(x)]-[13.03*(exp(x+dx(i))*cos(x+dx(i)))]+[18.19*(exp(x+(2*dx(i))))*cos(x+2*dx(i))]-[13.33*exp(x+3*dx(i))*cos(x+3*dx(i))]+[5.24*exp(x+4*dx(i))*cos(x+4*dx(i))]-[0.86*exp(x+5*dx(i))*cos(x+5*dx(i))])/[dx(i)^2];
%skewed left sided difference
SLSD(i)=([3.79*exp(x)*cos(x)]-[13.03*(exp(x-dx(i))*cos(x-dx(i)))]+[18.19*(exp(x-(2*dx(i))))*cos(x-2*dx(i))]-[13.33*exp(x-3*dx(i))*cos(x-3*dx(i))]+[5.24*exp(x-4*dx(i))*cos(x-4*dx(i))]-[0.86*exp(x-5*dx(i))*cos(x-5*dx(i))])/[dx(i)^2];
% central difference
CD(i)=([-0.0833*exp(x-(2*dx(i)))*cos(x-(2*dx(i)))]+[1.33*exp(x-dx(i))*cos(x-dx(i))]-[2.5*exp(x)*cos(x)]+[1.33*exp(x+dx(i))*cos(x+dx(i))]-[0.0833*exp(x+(2*dx(i)))*cos(x+(2*(dx(i))))])/((dx(i)^2));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
error_1(i)=abs(analytical-SRSD(i));
error_2(i)=abs(analytical-SLSD(i));
error_3(i)=abs(analytical-CD(i));
endfor
loglog(dx,error_1,\'*\')
hold on
loglog(dx,error_2,\'-@\')
hold on
loglog(dx,error_3,\':b\')
xlabel(\'step size\');
ylabel(\'error\');
legend(\'SRSD\',\'SLSD\',\'CD\');

After running the code that we just created then we\'ll get the graphs for different types of errors.

As we these results we can say that the error produced by central scheme is higher than the other two schemes. This is because of the no. of terms in central scheme, which are less than the other two.

As we increase the step size the error values are decreasing in all three difference schemes.

The FDS and BDS cannot do at starting and ending points respectively. But central difference scheme can do that. When you compare these with Forward Aprroximation and Rearward Approximation, these skewed schemes will do better than those because of no. of points.

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.