Project

Taylor table skewed method MATLAB PROGRAM

Matlab program for three solving approximations

  • Central difference
  • Skewed right sided difference
  • Skewed left sided difference
clear all
close all
clc

% function=exp(x)*cos(x)

x=pi/3;
dx=pi/40;

% analytical derivative=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);


% fourth order approximation using central differencing

central_differencing=(-2.1432*exp(x-2*dx)*cos(x-2*dx)+20.5716*exp(x-dx)*cos(x-dx)-36.8568*exp(x)*cos(x)+20.5716*exp(x+dx)*cos(x+dx)-2.1432*exp(x+2*dx)*cos(x+dx))/(12*dx^2);

% skewed right side differencing
skewed_right_side_differencing= (35*exp(x)*cos(x)-104*exp(x+dx)*cos(x+dx)+114*exp(x+2*dx)*cos(x+2*dx)-56*exp(x+3*dx)*cos(x+3*dx)+11*exp(x+4*dx)*cos(x+4*dx))/(12*dx^2);

% skewed left side diffrencing
skewed_left_side_differencing=(11*exp(x-4*dx)*cos(x-4*dx)-56*exp(x-3*dx)*cos(x-3*dx)+114*exp(x-2*dx)*cos(x-2*dx)-104*exp(x-dx)*cos(x-dx)+35*exp(x)*cos(x))/(12*dx^2);

% error

error_central_differencing=abs(central_differencing-analytical_derivative);
error_skewed_right_side_differencing=abs(skewed_right_side_differencing-analytical_derivative);
error_skewed_left_side_differencing=abs(skewed_left_side_differencing-analytical_derivative);

%comparison with FDS and BDS Methods

forward_difference=((exp(x+dx)*cos(x+dx))-(exp(x)*cos(x)))/dx;
backward_difference=((exp(x-dx)*cos(x-dx))-(exp(x)*cos(x)))/dx;

error_fds= abs(forward_difference-analytical_derivative);
error_bds=abs(backward_difference-analytical_derivative);

fname={\'central differece\',\'skewed right \',\'skewed left\',\'forward difference\',\'backward difference\'};
figure(1)
x=1:5;
y=[error_central_differencing error_skewed_right_side_differencing error_skewed_left_side_differencing error_fds error_bds];

bar(x,y);
set(gca,\'xTick\',1:length(fname),\'xTickLabel\',fname);
xlabel(\'scheme\')
ylabel(\'truncation error\')


 

Function of Central differencing :

function out=central_differencing(x,dx)


% function=exp(x)*cos(x)
% analytical derivative=-2*exp(x)*sin(x)

analytical_derivative=-2*exp(x)*sin(x);

% numerical derivative
central_differencing=(-2.1432*exp(x-2*dx)*cos(x-2*dx)+20.5716*exp(x-dx)*cos(x-dx)-36.8568*exp(x)*cos(x)+20.5716*exp(x+dx)*cos(x+dx)-2.1432*exp(x+2*dx)*cos(x+dx))/(12*dx^2);

out=abs(central_differencing-analytical_derivative);
end

Function of Right side differencing:

function out=skewed_right_side_differencing(x,dx)


% function=exp(x)*cos(x)
% analytical derivative=-2*exp(x)*sin(x)

analytical_derivative=-2*exp(x)*sin(x);

% numerical derivative
skewed_right_side_differencing=(35*exp(x)*cos(x)-104*exp(x+dx)*cos(x+dx)+114*exp(x+2*dx)*cos(x+2*dx)-56*exp(x+3*dx)*cos(x+3*dx)+11*exp(x+4*dx)*cos(x+4*dx))/(12*dx^2);

out=abs(skewed_right_side_differencing-analytical_derivative);
end

Left side differencing:

function out=skewed_left_side_differencing(x,dx)


% function=exp(x)*cos(x)
% analytical derivative=-2*exp(x)*sin(x)

analytical_derivative=-2*exp(x)*sin(x);

% numerical derivative
skewed_left_side_differencing=(11*exp(x-4*dx)*cos(x-4*dx)-56*exp(x-3*dx)*cos(x-3*dx)+114*exp(x-2*dx)*cos(x-2*dx)-104*exp(x-dx)*cos(x-dx)+35*exp(x)*cos(x))/(12*dx^2);

out=abs(skewed_left_side_differencing-analytical_derivative);
end

REsult:

\"\"

Result:

skewed Central Differences are a second-order accurate average of right-skewed & left skewed scheme with un-symmetric in grids. where the central difference scheme is symmetric grids right

The central difference method uses the data from both sides of point of interest to calculate the results. On the other hand, left and right skewed difference methods require data only from one side of point of interest to calculate the results. We can thus realise that the later methods are handy when we have the information about only one side of point of interest. For example, fluid flow through a pipe from one end to other. Here, central difference method will not work due to lack of sufficient data.

On the other hand, central difference method is more accurate than skewed methods. This is because central difference method takes data from points that are nearby the point of interest and thus contain more accurate information about the point. Skewed methods take data from points that are very far off from the point of interest and thus contain less accurate information about the point.

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.