Challenge

Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method

MATLAB CODES

1.CENTRAL DIFFERENCING

clear all
close all
clc
%value of x
x= pi/5;
%range of dx
dx= linspace(pi/7,pi/7000,10);
%for loop
for i=1:length(dx)
CD(i) = FOCD(x,dx(i));%fourth order central_differencing
end
%plotting
figure(1)
loglog(dx,CD,'g*-')
xlabel('range of dx')
ylabel('truncation error')
title('range of dx vs error')
legend('central differencing')

function Error_central_differencing = FOCD(x,dx)
% analytic function = exp(x)*cos(x)
% analytic derivative
analytical_derivative = -2*exp(x)*sin(x);
%numerical derivative
%central differencing
central_differencing = (((-0.0833)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))+((1.3333)*((exp(x-dx))*(cos(x-dx))))-...
((2.5000)*((exp(x))*(cos(x))))+((1.3333)*((exp(x+dx))*(cos(x+dx))))-((0.0833)*((exp(x+(2*dx)))*(cos(x+...
(2*dx))))))/(dx^2);
%error
Error_central_differencing = abs(central_differencing- analytical_derivative);
end

PLOT

2.SKEWED RIGHT SIDED DIFFERENCE:

clear all
close all
clc
%value of x
x= pi/5;
%range of dx
dx= linspace(pi/7,pi/7000,10);
%for loop
for i=1:length(dx)
RSS(i) = FORSS(x,dx(i));% fourth order right sided skew

end
%plotting
figure(1)
loglog(dx,RSS,'ro-')
xlabel('range of dx')
ylabel('truncation error')
title('range of dx vs error')
legend('skewed right sided difference')
function Error_right_sided_skew = FORSS(x,dx)
% analytic function = exp(x)*cos(x)
% analytic derivative
analytical_derivative = -2*exp(x)*sin(x);
%numerical derivative
%central differencing
right_sided_skew = (((3.7500)*((exp(x))*(cos(x))))-((12.8333)*((exp(x+dx))*(cos(x+dx))))+((17.8333)*((exp(x+...
(2*dx)))*(cos(x+(2*dx)))))-((13.0000)*((exp(x+(3*dx)))*(cos(x+(3*dx)))))+((5.0833)*((exp(x+(4*dx)))*(cos(x+...
(4*dx)))))-((0.8333)*((exp(x+(5*dx)))*(cos(x+(5*dx))))))/(dx^2);
%error
Error_right_sided_skew = abs(right_sided_skew- analytical_derivative);
end

PLOT

3.SKEWED LEFT SIDED DIFFERENCE:

clear all
close all
clc
%value of x
x= pi/5;
%range of dx
dx= linspace(pi/7,pi/7000,10);
%for loop
for i=1:length(dx)
LSS(i) = FOLSS(x,dx(i));% fourth order left sided skew
end
%plotting
figure(1)
loglog(dx,LSS,'m*-')
xlabel('dx')
ylabel('truncation error')
title('range of dx vs error')
legend('skewed left sided difference')

function Error_left_sided_skew = FOLSS(x,dx)
% analytic function = exp(x)*cos(x)
% analytic derivative
analytical_derivative = -2*exp(x)*sin(x);
%numerical derivative
%central differencing
left_sided_skew = (((-0.8333)*((exp(x-(5*dx)))*(cos(x-(5*dx)))))+((5.0833)*((exp(x-(4*dx)))*(cos(x-(4*dx)))))-...
((13.0000)*((exp(x-(3*dx)))*(cos(x-(3*dx)))))+((17.8333)*((exp(x-(2*dx)))*(cos(x-(2*dx)))))-((12.8333)*...
((exp(x-dx))*(cos(x-dx))))+((3.7500)*((exp(x))*(cos(x)))))/(dx^2);
%error
Error_left_sided_skew = abs(left_sided_skew- analytical_derivative);
end

PLOT

CONCLUSION

The central differencing scheme has very less error compared to other schemes. Therefore, central differencing is better than other schemes because it uses information from both the sides from the point of consideration to give approximative and accurate values.
As the left and right skewed difference methods uses data only from one side of point of interest it gives less approximative and accurate values about
the point.
USEFULLNESS OF SKEWED SCHEME :
The system which doesn’t contain sufficient information on both side of the point of interest. In such cases we cannot use central differencing scheme so
skewed scheme is useful in such cases.
SKEWED SCHEME is better than CD SCHEME:
CDS cannot not be employed at the boundary nodes due to unavailability of right and left nodes at the same time. In such cases the skewed differencing
scheme is used.

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.