Challenge

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

Derive the following 4th order approximations of the second-order derivative.

we use taylor table method for different nodes

1)Central difference scheme

We know that for CDS i varies from (i-2),(i-1),i,(i+1),(i+2)

now unknowns are solved by using matrix

%central difference
[E1]=[1 1 1 1 1;-2 -1 0 1 2;2 1/2 0 1/2 2;-8/6 -1/6 0 1/6 8/6;16/24 1/24 0 1/24 16/24];
[F1]=[0;0;1;0;0];
Central=rats(linsolve(E1,F1));
disp(Central)

outputs a,b,c,d and e are

2)Skewed right difference scheme

We know that for CDS i varies from i,(i+1),(i+2),(i+3),(i+4),(i+5)

now unkowns are solved by forming a matrix

%Skew right
[A1]=[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];
[B1]=[0;0;1;0;0;0];
SK_right=rats(linsolve(A1,B1));
disp(SK_right)

outputs a,b,c,d,e and g are

3)Skewed left difference scheme

We know that for CDS i varies from i,(i-1),(i-2),(i-3),(i-4),(i-5)

now unknowns are formed by solving a matrix

%skew left
[C1]=[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];
[D1]=[0;0;1;0;0;0];
SK_left=rats(linsolve(C1,D1));
disp(SK_left)

outputs a,b,c,d,e and g are

Matlab main program

clear all
close all
clc

x=pi/3;
dx=linspace(pi/4,pi/400,99);
%analytical function=e^x*cos(x)
analytical_derivative=-2*exp(x)*sin(x);

now for loop is used to compute varying values of dx

for i=1:length(dx)
    
    a(i)=(exp(x-(5*dx(i)))*cos(x-(5*dx(i))));
    b(i)=(exp(x-(4*dx(i)))*cos(x-(4*dx(i))));
    c(i)=(exp(x-(3*dx(i)))*cos(x-(3*dx(i))));
    d(i)=(exp(x-(2*dx(i)))*cos(x-(2*dx(i))));
    e(i)=(exp(x-dx(i))*cos(x-dx(i)));
    f(i)=(exp(x)*cos(x));
    g(i)=(exp(x+dx(i))*cos(x+dx(i)));
    h(i)=(exp(x+(2*dx(i)))*cos(x+(2*dx(i))));
    j(i)=(exp(x+(3*dx(i)))*cos(x+(3*dx(i))));
    k(i)=(exp(x+(4*dx(i)))*cos(x+(4*dx(i))));
    l(i)=(exp(x+(5*dx(i)))*cos(x+(5*dx(i))));
    
   %central difference scheme
   CDS(i)=(-1*(d(i))+16*(e(i))-30*(f(i))+16*(g(i))-1*(h(i)))/(12*(dx(i)^2));
   
   %skew right sided differnce
   skew_right(i)=(45*(f(i))-154*(g(i))+214*(h(i))-156*(j(i))+61*(k(i))-10*(l(i)))/(12*(dx(i)^2));
   
   %skew left sided difference
   skew_left(i)=(45*(f(i))-154*(e(i))+214*(d(i))-156*(c(i))+61*(b(i))-10*(a(i)))/(12*(dx(i)^2));
   
   error_CDS(i)=abs(CDS(i)-analytical_derivative);
   error_SKR(i)=abs(skew_right(i)-analytical_derivative);
   error_SKL(i)=abs(skew_left(i)-analytical_derivative);
end

The above equations in program are got substituing values a,b,c,d and e for respective schemes in below eqn

1)CDS equation is (a*(f-2)+b*(f-1)+c*(f)+d*(f+1)+e(f+2))/(dx^2)=f''(i)

2)skew right scheme is (a*f(i)+b*(f+1)+c*(f+2)+d*(f+3)+e(f+4)+g(f+5))/(dx^2)=f''(i)

3)skew left scheme is (a*f(i)+b*(f-1)+c*(f-2)+d*(f-3)+e(f-4)+g(f-5))/(dx^2)=f''(i)

figure
loglog(dx,error_CDS,'linewidth',1,'marker','hexagram')
hold on
loglog(dx,error_SKR,'linewidth',1,'marker','pentagram')
loglog(dx,error_SKL,'linewidth',1,'marker','d')
grid on
xlabel('dx')
ylabel('Absolute Error')
legend('central difference','skew right difference','skew left differnce','location','northwest')
title('absolute error between various finite differnce schemes')

Skew scheme is useful because when data of grid points is avialable only either from left end or right end.we use skew scheme for higher order approximations but when CDS we need data of both sides

CONCLUSION: CDS contains less error compared other schemes

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.