Project

derivation of 4th order approximation of 2nd order difference using central,forward and backward difference

(1) Central difference scheme:

`(d^2f)/(dx^2)=(a.f(i-2)+b.f(i-1)+c.(i)+d(i+1)+e.f(i+2))/(Delta*x^2)`

The coefficient of 2nd derivative of x is 1 while that of other derivatives is zero and of 6th derivative of x is an unknown finite term (which is considered as the error term).Thus, in the error term, the power of delta(x) is 4. This confirms that the approximation is of order 4.

(2).Forward difference scheme:

`(d^2f)/(dx^2)=(a.f(i)+b.f(i+1)+c.f(i+2)+d.f(i+3)+e.f(i+4))/(Delta*x^2)`

The coefficient of 2nd derivative of x is 1 while that of other derivatives is zero and of 6th derivative of x is an unknown finite term (which is considered as the error term).Thus, in the error term, the power of delta(x) is 4. This confirms that the approximation is of order 4.

(3).Backward difference scheme:

`(d^2f)/(dx^2)=(a.f(i)+b.f(i-1)+c.f(i-2)+d.f(i-3)+e.f(i-4))/(Delta*x^2)`

The coefficient of 2nd derivative of x is 1 while that of other derivatives is zero and of 6th derivative of x is an unknown finite term (which is considered as the error term).Thus, in the error term, the power of delta(x) is 4. This confirms that the approximation is of order 4.

MATLAB SCRIPT:

close all
clear all
clc

%%function of taylor series
%f(x)=exp(x)*cos(x)
x=pi/4;
dx=linspace(pi/20,pi/400,40);
real_derivation=-2*exp(x)*sin(x);

for i=length(dx)
[central_difference(i),central_err(i),forward_difference(i),forward_err(i),backward_difference(i),backward_err(i)]=taylor_series_expansion(x,dx(i),real_derivation);
end

figure(1)
loglog(dx,central_err,'g',dx,forward_err,'r',dx,backward_err,'b')
xlabel('log(dx)');
ylabel('error')
legend('central_difference','forward_difference','backward_difference')
title('comparision of errors')

FUNCTION:

function [central_difference,central_err,forward_difference,forward_err,backward_difference,backward_err]=taylor_series_expansion(x,dx,real_derivation)

%%central differece
central_difference=(-1*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))-1*(exp(x-(2*dx))*cos(x-(2*dx))))./12*(dx.^2);
%error
central_err=abs(real_derivation-central_difference);

%%forward difference
forward_difference=(45*exp(x)*cos(x)-154*exp(x+dx)*cos(x+dx)+214*exp(x+(2*dx))*cos(x+(2*dx))-156*exp(x+(3*dx))*cos(x+(3*dx))+61*exp(x+(4*dx))*cos(x+(4*dx))-10*exp(x+(5*dx))*cos(x+(5*dx)))./12*(dx.^2);
%forward error
forward_err=abs(real_derivation-forward_difference);

%%backward difference
backward_difference=(45*exp(x)*cos(x)-154*exp(x-dx)*cos(x-dx)+214*exp(x-(2*dx))*cos(x-(2*dx))-156*exp(x-(3*dx))*cos(x-(3*dx))+61*exp(x-(4*dx))*cos(x-(4*dx))-10*exp(x-(5*dx))*cos(x-(5*dx)))./12*(dx.^2);

%error
backward_err=abs(real_derivation-backward_difference);
end

CONCLUSIONS:

(1) As seen from the figures, the error of the central difference method is very less compared to the skewed methods. Also, because of its faster convergence rates CDS is preferred over skewed method.

(2) Forward and backward difference methods almost give the same results in terms of error for a small value of time-step.

(3) CDS cannot be employed at boundary nodes due to the unavailability of forward and backward nodes at the same time. In such cases, forward or backward differencing scheme is used depending on the direction of flow of information.

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.