Challenge

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

OBJECTIVE:

To drive the fourth-order approximations of a second-order derivative using the central differencing scheme, skewed right-sided difference, and skewed left-sided difference with the help of the Taylor table method and to compare the analytical derivative with obtained values for a given function.

CENTRAL DIFFERENCE SCHEME:

NO OF NODES:

No of nodes = p+q-1

Where p is the order of derivative

q is the order of approximations

the number of nodes = 2+4-1=.>5

DERIVATION:

To derive a fourth-order approximation for the second-order derivative, we start with approximation:

Taylor series deviation for the above term is :

expanding all the terms in the above equation and represented in form of the table using the Taylor table method

the linear equation obtained from the above table are solved using matrix inversion method

A.X = B

X = inv(A)*B

therefore a = -0.0833

b = 1.333

c = -2.5000

d = 1.333

e = -0.0833

therefore the main equation comes out to be =

SKEWED RIGHT HAND DIFFERENCE SCHEME:

No of nodes = p+q

where p is order of derivative

q = order of approximations

the number of nodes = 2+4 =>6

DERIVATION:

to derive a fourth order approximation for the second order derivative, we start with these approximation

expanding using Taylor series expansion and are represented in form of the table using the Taylor series method.

the linear equation obtained from above is solved using the matrix inversion method :

X = inv(A)*B, on solving we get

a =3.750, b =-12.833, c =17.833, d = -13.000, e = 5.0833, f = -0.833

substituting in equation, we get final equation as :

SKEWED LEFT HAND DIFFERENCE SCHEME:

The No of Nodes =p+q

p = number of derivative

q = number of approximations

therefore the number of nodes = 2+4=>6

To drive a fourth-order approximation for the second-order derivative, we start with approximation:

expanding all the term in above equation using taylor series expansion and representing in table method according to taylor table method:

the linear equation obtained from the above table are solved using matrix inversion :

x =inv(A)*B

a = -0.833, b = 5.0833, c = -13.000, d = 17.8333, e = -12.8333, g = 3.7500

substituting these coefficients in above equations, we get

MAIN CODE :

clear all
close all
clc

% value of x
x =pi/3;


%range of dx
dx =linspace(pi/4,pi/4000,20);


% for loop
for i = 1:length(dx)

central_differencing(i) = fourth_order_central_differencing(x,dx(i))
right_sided_skew(i)=fourth_order_right_sided_skew(x,dx(i))
left_sided_skew(i)=fourth_order_left_sided_skew(x,dx(i))


end


%plotting
figure(1)
loglog(dx,central_differencing,'r')
hold on
loglog(dx,right_sided_skew,'g')
hold on
loglog(dx,left_sided_skew,'b')


xlabel('range of x')
ylabel('trucation of error')
title('range of dx vs error')
legend('central differencing','skewed right sided difference','skewed left sided difference','location','northwest')

FUNCTION CODE FOR CENTERAL DIFFERENCING :

function Error_central_differencing = fourth_order_central_differencing(x,dx)


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


%analytical derivative
% f''(x) = -2*exp(x)*sin(x)


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


%numerical derivative


%centeral 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

FUNCTION CODE FOR SKEWED RIGHT SIDED DIFFERENCE:

function Error_right_sided_skew = fourth_order_right_sided_skew(x,dx)


%analytical fumnction = exp(x)*cos(x)


% f''(x) = -2*exp(x)*sin(x)
analytical_derivative = -2*exp(x)*sin(x);


%numerical derivative


%centeral 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

FUNCTION CODE FOR SKEWED LEFT SIDED DIFFERENCE:

function Error_left_sided_skew = fourth_order_left_sided_skew(x,dx)


%analytical fumnction = exp(x)*cos(x)


% f''(x) = -2*exp(x)*sin(x)
analytical_derivative = -2*exp(x)*sin(x);


%numerical derivative


%centeral 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_left_sided_skew = abs(left_sided_skew-analytical_derivative);
end

OUTPUT:

CONCLUSION:

  • as we can see from the plot that central differencing has less error compared to the left and right-skewed differences.
  • as the central differencing uses both sides from point of consideration to giving approximating and accurate values.
  • as left and right-skewed difference, methods use data only from one side of interest therefore it gives less approximating and accurate values
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.