Challenge

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

  1. Aim:

Derive fourth-order approximations of the second-order derivative using the central differential scheme, skewed right-sided difference, and skewed left-sided difference using the Taylor table method and compare the analytical derivative with the obtained values ​​for the given function

  1. Central difference
  2. Skewed right-sided difference
  3. Skewed left-sided difference

Interesting fact: Why is a higher order approximation desirable in the first place?

We can gain higher precision, fewer mesh points, less calculation time, and less storage for the same mesh. Consequently, any computation that needs the resolution of tiny length scales (i.e., the crucial physics happens on small length scales) or has extremely steep spatial gradients is a prime candidate for higher order differentiation.

SCHEME DERIVATIONS:

CENTRAL DIFFERENCING SCHEME:

NO OF NODES:

The number of nodes = p+q-1

Where, p is order of derivative.

q is order of approximations.

The no of nodes = 2+4-1 =>5

DERIVATION:

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

taylor series derivation for the above terms,

Simillarly expand all the terms in the equation (1) and are represented in the form of table using taylor table method.

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

A.X = B

X = inv(A)*B

we get the coefficients as,

a=-0.0833, b=1.3333, c=-2.5000, d=1.3333 e=-0.0833

substituting these coefficient in equation(1) we get,

SKEWED RIGHT HAND DIFFERENCE SCHEME:

NO OF NODES:

The number of nodes = p+q

Where, p is order of derivative.

q is order of approximations.

The no of nodes = 2+4 =>6.

DERIVATION:

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

expand all the terms in the equation (2) using taylor series expansion and are represented in the form of table using taylor table method

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

A.X = B

X = inv(A)*B

we get the coefficients as,

a=3.7500, b=-12.8333, c=17.8333, d=-13.0000 e=5.0833 g=-0.8333

substituting these coefficient in equation(3) we get

SKEWED LEFT HAND DIFFERENCE SCHEME:

NO OF NODES:

The number of nodes = p+q

Where, p is order of derivative.

q is order of approximations.

The no of nodes = 2+4 =>6

DERIVATION:

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

expand all the terms in the equation (3) using taylor series expansion and are represented in the form of table using taylor table method

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

A.X = B

X = inv(A)*B

we get the coefficients as,

a=-0.8333, b=5.0833, c=-13.0000, d=17.8333 e=-12.8333 g=3.7500

function codes central differencing;

function Error_central_differencing = fourth_order_central_differencing(x,dx)

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

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

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

function code for right sided skew;

function Error_right_sided_skew = fourth_order_right_sided_skew(x,dx)

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

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

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

function code for left sided skew;

function Error_left_sided_skew = fourth_order_left_sided_skew(x,dx)

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

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

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

Matlab main code;

clear all
close all
clc

%value of x
x= pi/3;

%range of dx
dx= linspace(pi/40,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 dx')
ylabel('truncation error')
title('range of dx vs error')
legend('central differencing','skewed right sided difference','skewed left sided difference','location','northwest')

OUTPUT:

CONCLUSION:

The central difference scheme has far less mistakes than other schemes, as seen in the graph. Since central differencing employs data from both sides of the argument to produce both approximate and precise values, it is preferable than other systems.
The left-right skewed difference approach delivers less precise and approximative values about the point since it only takes data from one side of the point of interest.
WHAT MAKES A TRIED SCHEME USEFUL:
A system that is missing necessary data on both sides of the point of interest. The skew scheme is helpful in these situations since we are unable to employ the central difference scheme.
WHY A SLIP SCHEME IS BETTER THAN A CD SCHEME:
Due to the absence of simultaneous right and left nodes, CDS cannot be utilised on border nodes. The skewed difference approach is applied in these circumstances.
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.