Challenge

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

Derivation:-

to derive the fourth order approximation for the second order  derivative .

`(del^2 u)/(delx^2)=(af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2))/dx-------------(1)`

taylor series derivation  above eqaution.

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

Using taylor method express in table form

dx2 f''(i)              f(i)                     f'(i)dx                   f''(i)dx2                 f'''(i)dx3                f''''(i) dx4

af(i-2)                 a                         -2a                       2a                        -4a/3                       2a/3

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                        2e                            4e/3                      2e/3

sum of                0                           0                           1                             0                            0

cofficient

euation conert into the  matrix form

AX=B

<!--[endif]--><!--[endif]-->


<!--[endif]--><!--[endif]-->

x=inv(A)*B

respectively cofficient values.

Values put in equation (1):-

a=-0.8333

b=1.3333

c=-2.5000

d=1.3333

e=-0.0833

`(del^2 u)/(delx^2)=((0.0833)f(i-2)+(1.3333)f(i-1)+(-2.5000)f(i)+(1.3333)f(i+1)+(0.0833)f(i+2))/dx`

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,

`(del^2u)/(delx^2)=(af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5))/dx^2`-----------------------(2)

       

Using taylor method express in table form

`dx^2f''(i)` f(i)  f'(i)dx  f''(i)dx2 f'''(i)dx3  f''''(i) dx4 `f'''''(i) dx^5`
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`
sum of co-efficients 0 0      1        0        0          0

 Linera eqaution convert into the mtrix form;-

AX=B

`[[1,1,1,1,1,1],[0,1,2,3,4,5],[0,1/2,4/2,9/2,16/2,25/2],[0,1/6,8/6,27/6,64/6,125/6],[0,1/24,16/24,81/24,256/24,625/24],[0,1/120,32/120,243/120,1024/120,3125/120]]`.`[(a),(b),(c),(d),(e),(g)]`=`[(0),(0),(1),(0),(0),(0)]`

x=inv(A)*B

 

a=3.7500

b=-12.8333

c=17.83333

d=13.0000

e=-12.8333

g=-0.8333

Subsistue these values in equation-(2)

`(del^2u)/(delx^2)=((3.7500)f(i)+(12.8333)f(i+1)+(-17.8333)f(i+2)+(-13.0000)f(i+3)+(5.0833)f(i+4)+(-0.8333)f(i+5))/dx^2`

skewed left hand differnce scheme:-

no of nodes

=p+q

Where, p is order of derivative.

           q is order of approximations.

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

derivation

fourth order approximation for the second order derivation:-

 `(del^2u)/(delx^2)=(af(i-5)+bf(i-4)+cf(i-3)+df(i-2)+ef(i-1)+gf(i))/dx^2`------------------(3)

`dx^2f''(i)` f(i)  f'(i)dx  f''(i)dx2 f'''(i)dx3  f''''(i) dx4 `f'''''(i) dx^5`
af(i-5) a -5a `(25a)/2` ``-(125a)/6`` ``-(625a)/25`` `-(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`
sum of co-efficients 0 0   1     0     0     0

 

 linear Equation in matrix form:-

AX=B

``[[1,1,1,1,1,1],[-5,-4,-3,-2,-1,0],[25/2,16/2,9/2,4/2,1/2,0],[-125/6,-64/6,-27/6,-8/6,-1/6,0],[625/24,256/24,81/24,16/24,1/24,0],[-3125/120,-1024/120,-243/120,-32/120,-1/120,0]]``.`[(a),(b),(c),(d),(e),(g)]`=`[(0),(0),(1),(0),(0),(0)]`

x=inv(A)*B

 

 a= -0.8333

b= 5.0833

c=-13.0000 

d= 17.83333

g=3.7500

Subsistue these values in equation-(3)

`(del^2u)/(delx^2)=((-0.8333)f(i-5)+(5.0833)f(i-4)+(13.0000)f(i-3)+(17.8333)f(i-2)+(-12.8333)f(i-1)+(3.7500)f(i))/dx^2`

 Matlab  Code:-

FOURTH ORDER CENTRAL DIFFERNCING:-

function error_cental_differncing=fourth_central_differncing(x,dx)
% anyltic function =exp(x)*cos(x)
%analytic_derivative
% f'(x)=exp(x)*cos(x)-exp(x)*sin(x)
% f''(x)=-2*exp(x)*sin(x)
analytic_derivative=-2*exp(x)*sin(x);

%numerical_derivative
�ntral differncing
central_differncing=(((-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_cental_differncing=abs(central_differncing-analytic_derivative);
end

 SKEWED RIGHT HAND DIFFERENCE SCHEME:

function error_skewed_right_hand=fourth_order_skewed_right_differnce(x,dx)
% anyltic function =exp(x)*cos(x)
%analytic_derivative
% f'(x)=exp(x)*cos(x)-exp(x)*sin(x)
% f''(x)=-2*exp(x)*sin(x)
analytic_derivative=-2*exp(x)*sin(x);

%numerical_derivative
�ntral differncing
right_side_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_skewed_right_hand=abs(right_side_skew-analytic_derivative);
end

 SKEWED LEFT HAND DIFFERENCE SCHEME:

function error_skewed_left_hand=fourth_order_skewed_left_differnce(x,dx)
% anyltic function =exp(x)*cos(x)
%analytic_derivative
% f'(x)=exp(x)*cos(x)-exp(x)*sin(x)
% f''(x)=-2*exp(x)*sin(x)
analytic_derivative=-2*exp(x)*sin(x);

%numerical_derivative
�ntral differncing
left_side_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_skewed_left_hand=abs(left_side_skew-analytic_derivative);
end

MAIN CODE:-

close all
clear all
clc
% value of x
x=pi/3;
% range of dx
dx=linspace(pi/4,pi/4000,20);

for i=1:length(dx)
    central_differncing(i)=fourth_central_differncing(x,dx(i));
    right_side_skew(i) =fourth_order_skewed_right_differnce(x,dx(i));
   left_side_skew(i) =fourth_order_skewed_left_differnce(x,dx(i));
end

figure(1)
loglog(dx,central_differncing)
hold on
loglog(dx,right_side_skew,'r')
hold on
loglog(dx,left_side_skew,'g')
xlabel('range of dx')
ylabel('truncation error')
legend('central differncing','right side skew','left side skew')

LOGLOG GRAPH REPRESNTION

Conclusion:-

as per graph curve central differncing is very  less error as compared to the right side skews  scheme & left side skews scheme.ln the left and right skewed differnce method  uses data only it gives the approximate and accurate values.

Why skewed scheme is useful:- the system is dose not 

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.