Challenge

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

sceme derivation:

central differencing scheme:

no of nodes:

the number of nodes = p+q-1

p is order of derivatives

q is order of approximation

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

Derivation:

(∂^2u/∂x^2)=(af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2))/dx^2 (equation 1)

taylor series for (equation 1)

af(i-2) = af(x)-((2af'(x)dx)/1!)+((4af''(x)dx^2)/2!)+((8af'''(x)dx^3)/3!)+((16af''''(x)dx^4)/4!)

simillarly expends all the term in (equation 1) and using table of taylor table method.

f(x) △xf'(x) △x^2f''(x) △x^3f'''(x) △x^4f''''(x)
af(i-2) a -2a 4a/2 -8a/6 16a/24
bf(i-1) b -b b/2 -b/6 b/24
cf(i) c 0 0 0 0
df(i+1) d d d/2 d/6 d/24
ef(i+2) e 2e 4e/2 8e/6 16e/24
0 0 1 0 0

above table is solved invertion method

A.X = B

[1 1 1 1 1 [ a [0

-2 -1 0 1 2 b 0

2 1/2 0 1/2 1 . c = 1

-4/3 -1/6 0 1/6 4/3 d 0

2/3 1/24 0 1/24 2/3 ] e] 0]

answer of the values by getting solve the above equtaion

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

sub the value of above equation

(∂^2u/∂x^2)=(0.0833*(i-2)+1.3333*(i-1)-2.500*0(i)+1.3333*(i+1)-0.0833*(i+2))/dx^2

skewed right sided differencing scheme:

no of nodes:

the number of nodes = p+q

p is order of derivatives

q is order of approximation

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

Derivation:

(∂^2u/∂x^2)=(af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+(gf(i+5)/dx^2 (equation 2)

simillarly expends all the term in (equation 2) and using table of taylor table method.

f(x) △xf'(x) △x^2f''(x) △x^3f'''(x) △x^4f''''(x) △x^5f'''''(x)
af(i) a 0 0 0 0 0
bf(i+1) b b b/2 b/6 b/24 b/120
cf(i+2) c 2c 4c/2 8c/6 16c/24 32c/120
df(i+3) d 3d 9d/2 27d/6 81d/24 243d/120
ef(i+4) e 4e 16e/2 64e/6 256e/24 1024e/120
gf(i+5) g 5g 25g/2 125g/6 625g/24 3125g/120
0 0 1 0 0 0

above table is solved invertion method

A.X = B

[1 1 1 1 1 1 [ a [0

0 1 2 3 4 5 b 0

0 1/2 2 9/2 16/2 25/2 . c = 1

0 1/6 4/3 9/2 32/3 125/6 d 0

0 1/24 2/3 9/2 25/24 625/24 e 0

0 1/120 4/15 243/120 1024/120 3125/120 g 0]

answer of the values by getting solve the above equtaion

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

sub the value of above equation

(∂^2u/∂x^2)=(3.7500*f(i)-12.8333*f(i+1)+17.8333*f(i+2)-13.000*f(i+3)+5.08333*f(i+4)-(0.8333*f(i+5))/dx^2

skewed left sided differencing scheme:

no of nodes:

the number of nodes = p+q

p is order of derivatives

q is order of approximation

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

Derivation:

(∂^2u/∂x^2)=(af(i-5)+bf(i-4)+cf(i-3)+df(i-2)+ef(i-1)+(gf(i)/dx^2 (equation 2)

simillarly expends all the term in (equation 2) and using table of taylor table method.

f(x) △xf'(x) △x^2f''(x) △x^3f'''(x) △x^4f''''(x) △x^5f'''''(x)
af(i-5) a -5a 25a/2 -125a/6 625a/24 -3125a/120
bf(i-4) b -4b 16b/2 -64b/6 256b/24 -1024b/120
cf(i-3) c -3c 9c/2 -27c/6 81c/24 -243c/120
df(i-2) d -2d 4d/2 -8d/6 16d/24 -32d/120
ef(i-1) e -e e/2 -e/6 e/24 -e/120
gf(i) g 0 0 0 0 0
0 0 1 0 0 0

above table is solved invertion method

A.X = B

[1 1 1 1 1 1 [ a [ 0

-5 -4 -3 -2 -1 0 b 0

25/2 16/2 9/2 2 1/2 0 . c = 1

-125/6 -64/6 -27/6 -8/6 -1/6 0 d 0

625/24 256/24 81/24 16/24 1/24 0 e 0

-3125/120 -1024/120 -243/120 -32/120 -1/120 0] g ] 0]

answer of the values by getting solve the above equtaion

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

sub the value of above equation

(∂^2u/∂x^2)=(-0.8333*f(i-5)+5.08333*f(i-4)-13.0000*f(i-3)+17.8333*f(i-2)-12.8333*f(i-1)+3.7500*f(i))/dx^2

coding for above derivatives:

%define first order function
function error_central_differencing = fourth_central_differencing(x,dx)
% function is F(x) = exp(x)*cos(x)
% Analytical derivative
%f''(x) = -2*exp(x)*sin(x)
analytivcal_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);

%storing the value
error_central_differencing=abs(central_differencing-analytivcal_derivative);
end

That a function named as fourth_central_differencing, In 6th line analytical derivation of the given function and it's calculated. After that, the central_differencing is calculated. at the end, truncation error is calculated.

%define fourth order function
function error_of_right_sided_skew = fourth_order_right_sided_skew(x,dx)
% function is F(x) = exp(x)*cos(x)
% Analytical derivative
%f''(x) = -2*exp(x)*sin(x)
analytivcal_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);
%storing the value
error_of_right_sided_skew=abs(right_sided_skew-analytivcal_derivative);
end

That a function named as fourth_order_right_sided_skew, In 6th line analytical derivation of the given function and it's calculated. After that, the fourth_order_right_sided_skew is calculated. at the end, truncation error is calculated.

%define first order function
function error_of_left_sided_skew = fouth_order_left_sided_skew(x,dx)
% function is F(x) = exp(x)*cos(x)
% Analytical derivative
%f''(x) = -2*exp(x)*sin(x)
analytivcal_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);
%storing the value
error_of_left_sided_skew=abs(left_sided_skew-analytivcal_derivative);
end

That a function named as fouth_order_left_sided_skew, In 6th line analytical derivation of the given function and it's calculated. After that, the fouth_order_left_sided_skew is calculated. at the end, truncation error is calculated.

Main code:

%derving fourth order approximation

clear all
close all
clc

%declaring the x value
x=pi/3;
% declaring the dx value
dx=linspace(pi/4000,pi/40,20);


% Range for dx

for i = 1:length(dx)
central_differncing(i) = fourth_central_differencing(x,dx(i));

skewed_right_side_differencing(i) = fourth_order_right_sided_skew(x,dx(i));

skewed_left_side_differencing(i) = fouth_order_left_sided_skew(x,dx(i));

end
%plotting the result
figure(1)
%using loglog commend for plotting colour graph
loglog(dx,central_differncing,'b')
hold on
loglog(dx,skewed_right_side_differencing,'g')
hold on
loglog(dx,skewed_left_side_differencing,'r')
xlabel('range of dx')
ylabel('trancation error')
title('range of dx vs errors')
legend('central differencing','skewed right side differencing','skewed left side differencing')

finally the error and dx value are plotted with tittle of "range of dx vs errors".

Conclusion:

Central differencing scheme has very less error to compare other schemes. so CDS is better than others.

Why a skewed scheme is useful:

If some insufficient data may given, that time can't use the central differencing scheme that time skewed scheme are used.

What can a skewed scheme do that a CD scheme cannot:

CD scheme cannot be employed at the boundary nodes due to unavailability of right and left side at the same point.in such a case skewed scheme are 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.