Project

To derive Central difference Skewed Left and Skewed Right side scheme by using Taylor table of finite difference method

Aim:-The aim of this project is to derive the central difference,skewed left,skewed right scheme for fourth order approximation of second order derivative by using Taylor table of finite difference method.

Main Program:-In this program all the subprogram(central difference, skewed left and skewed right) will be called and the result will be executed for a particular value of x and range of dx.

clear all
close all
clc

%Input parameter
x=pi/3;
dx=linspace(pi/5,pi/5000,100);

%Function=exp(x)*cos(x);

%Analytical_derivative;
%Second_order_analytical_derivative;
second_order_analytical_derivative=-2*sin(x)*exp(x);

%For loop;

for i=1:length(dx)

central_difference_error(i)=central_difference_scheme(x,dx(i));

skewed_right_side_error(i)=skewed_right_side_scheme(x,dx(i));

skewed_left_side_error(i)=skewed_left_side_scheme(x,dx(i));

end

%Plotting;
 figure(1)
 loglog(dx,central_difference_error,\'y\')
 hold on
 loglog(dx,skewed_right_side_error,\'g\')
 hold on
 loglog(dx,skewed_left_side_error,\'b\')
 
 %Labeling;
 xlabel(\'dx\')
 ylabel(\'error\')
 legend(\'central difference error\',\'skewed right side error\',\'skewed left side error\')
 legend(\'location\',\'northwest\')
 

1.Central difference scheme:-In central difference scheme the values are taken from both the side of the desired point(i.e.negative and positive).

The second order derivative equation used for fourth order approximation for CDS is:-

Taylor Table for fourth order approximation of Central Differencing scheme:-

Following program has been written in Octave to find the value of coefficient:-

clear all
close all
clc

%Finding constant for above table;
A=[1 1 1 1 1;-2 -1 0 1 2;2 0.5 0 0.5 2;-4/3 -1/6 0 1/6 4/3;2/3 1/24 0 1/24 2/3];

B=[0;0;1;0;0];

C=inv(A)*B

The value obtained are as follows:-

a=-0.083333
b=1.333333
c=-2.500000
d=1.333333
e=-0.083333

Program for Central differencing scheme:-

function out=central_difference_scheme(x,dx)

%Function=exp(x)*cos(x);

%Analytical_derivative;
%Second_order_analytical_derivative;
Second_order_analytical_derivative=-2*sin(x)*exp(x);

%Numerical_derivative;
%Fourth_order_approximation;

central_difference=(-0.0833*exp(x-2*dx)*cos(x-2*dx)+1.3333*exp(x-dx)*cos(x-dx)-2.50*exp(x)*cos(x)+1.3333*exp(x+dx)*cos(x+dx)-0.0833*exp(x+2*dx)*cos(x+2*dx))/dx^2;

out=abs(central_difference-Second_order_analytical_derivative);

end

2.Skewed right side scheme:-In skewed right side scheme the values are takrn only from the positive side of the desired point.

The second order derivative equation used for fourth order approximation for skewed right side scheme is:-

Taylor Table for fourth order approximation of skewed right side scheme:-

Following program has been written in Octave to find the value of coefficient:-

clear all
close all
clc

%Finding constant for above table;
A=[1 1 1 1 1 1;0 1 2 3 4 5;0 0.5 4/2 9/2 16/2 25/2;0 1/6 8/6 27/6 64/6 125/6;0 1/24 16/24 81/24 256/24 625/24;0 1/120 32/120 243/120 1024/120 3125/120];
B=[0;0;1;0;0;0];

C=inv(A)*B

The value obtained are as follows:-


a=3.75000
b=-12.83333
c=17.83333
d=-13.00000
e=5.08333
f=-0.83333

Program for right side skewed scheme:-

function out=skewed_right_side_scheme(x,dx)

%Function=exp(x)*cos(x);

%Analytical_derivative;
%Second_order_analytical_derivative;
second_order_analytical_derivative=-2*sin(x)*exp(x);

%Numerical_derivative;
%Fourth_order_approximation;

skewed_right_side=(3.75*exp(x)*cos(x)-12.83333*exp(x+dx)*cos(x+dx)+17.83333*exp(x+2*dx)*cos(x+2*dx)
                      -13*exp(x+3*dx)*cos(x+3*dx)+5.083333*exp(x+4*dx)*cos(x+4*dx)-0.83333*exp(x+5*dx)*cos(x+5*dx))/(dx^2);

out=abs(skewed_right_side-second_order_analytical_derivative);

end

3.Skewed left side scheme:-In this scheme the values are taken only from the negative side of the desired value.

The second order derivative equation used for fourth order approximation for skewed left side scheme is:-

Taylor Table for fourth order approximation of skewed left side scheme:-

Following program has been written in Octave to find the value of coefficient:-

clear all
close all
clc

%Finding coefficient for above table;
A=[1 1 1 1 1 1;0 -1 -2 -3 -4 -5;0 0.5 4/2 9/2 16/2 25/2;0 -1/6 -8/6 -27/6 -64/6 -125/6;0 1/24 16/24 81/24 256/24 625/24;0 -1/120 -32/120 -243/120 -1024/120 -3125/120];
B=[0;0;1;0;0;0];

C=inv(A)*B

The value obtained are as follows:-


a=3.75000
b=-12.83333
c=17.83333
d=-13.00000
e=5.08333
f=-0.83333

Program for left side skewed scheme:-

function out=skewed_left_side_scheme(x,dx)

%Function=exp(x)*cos(x);

%Analytical_derivative;
%Second_order_analytical_derivative;
second_order_analytical_derivative=-2*sin(x)*exp(x);

%Numerical_derivative;
%Fourth_order_approximation;

skewed_left_side=(3.75*exp(x)*cos(x)-12.83333*exp(x-dx)*cos(x-dx)+17.83333*exp(x-2*dx)*cos(x-2*dx)-13*exp(x-3*dx)*cos(x-3*dx)+5.083333*exp(x-4*dx)*cos(x-4*dx)-0.83333*exp(x-5*dx)*cos(x-5*dx))/dx^2;

out=abs(skewed_left_side-second_order_analytical_derivative);

end

The Output obtained from the above programs is as follow:-

Conclusion:-

  • It can be observed that right side skewed scheme gives maximum error as compared to the left side skewed and central differencing scheme.
  • Central differencing scheme is more stable as compared to the other schemes.

Now let\'s elaborate why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot do?

Ans:-Altough central differencing scheme gives less error as compared to skewed right and left side scheme but in some cases skewed difference schemes are more useful as compaed to the central difference scheme.We cannot apply central difference scheme at boundaries because it requires value from both sides but we can use the forward difference scheme and backward difference scheme at boundaries.The reason why we don\'t use them are because they have low order of approximations.

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.