Challenge

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

DERIVING 4TH ORDER APPROXIMATION OF A 2ND ORDER DERIVATIVE USING TAYLOR TABLE METHOD

Derivation of the 4th order Numerical approximations of the second-order derivative.

1. Central difference

`a*f(i-2)+b*f(i-1)+c*f(i)+d*f(i+1)+e*f(i+2)`

`(-0.083*f(x-2*dx)+1.33*f(x-dx)-2.5*f(x)+1.33*f(x+dx)-0.083*f(x-2*dx))/(dx^2)`

2. Skewed right-sided difference

`a*f(i)+b*f(i+1)+c*f(i+2)+d*f(i+3)+e*f(i+4)+g*f(i+5)`

`(3.75*f(x)-12.833*f(x+dx)+17.833*f(x+2*dx)-13*f(x+3*dx)+5.083*f(x+4*dx)-0.833f(x+5*dx))/(dx^2)`

3. Skewed left-sided difference

`a*f(i)+b*f(i-1)+c*f(i-2)+d*f(i-3)+e*f(i-4)+g*f(i-5)`

`(3.75*f(x)-12.833*f(x-dx)+17.833*f(x-2*dx)-13*f(x-3*dx)+5.083*f(x-4*dx)-0.833f(x-5*dx))/dx^2`

a,b,c,d,e,g are taylor table coefficient are found using matrix inversion method in Matlab.

For skewed schemes,

Order of accuracy,P=Number of nodes in the stencil,N- Order of derivative,Q

Number of nodes in the stencil,N = 6

Order of derivative,Q = 4

Order of accuracy,P=6-2=4

By deriving these schemes, proved that skewed schemes are fourth-order accurate.

Program in Matlab to evaluate the second-order derivative of the analytical function exp(x)*cos(x) and compare it with the 3 numerical approximations that you have derived.

Analytical function:

`f(x)=exp(x)*cos(x)`

First order derivative:

`f'(x)=exp(x)*(cos*x-sin*x)`

Second order derivative:

`f''(x)=-2*exp(x)*sin*x

MAIN PROGRAM:

clear all
close all
clc

x=pi/3;
dx=linspace(pi/30,pi/300,100);

B = [0 ;0 ;1 ;0 ;0 ;0];
A= [1 1 1 1 1 1;0 1 2 3 4 5;0 1/2 2 9/2 8 25/2;0 1/6 4/3 9/2 32/3 125/6;0 1/24 2/3 27/8 32/3 625/24;0 1/120 4/15 81/40 128/15 625/24];

D = [0 ;0 ;1 ;0 ;0 ;0];
C = [1 1 1 1 1 1;0 -1 -2 -3 -4 -5;0 1/2 2 9/2 8 25/2;0 -1/6 -4/3 -9/2 -32/3 -125/6;0 1/24 2/3 27/8 32/3 625/24;0 -1/120 -4/15 -81/40 -128/15 -625/24];


F=[0;0;1;0;0];
E=[1 1 1 1 1; -2 -1 0 1 2; 2 1/2 0 1/2 2; -4/3 -1/6 0 1/6 4/3;2/3 1/24 0 1/24 2/3];

[X,Y,Z] = num_discrete(A,B,C,D,E,F);

Analytical_derivative = -2*exp(x)*sin(x);
for i=1:length(dx)
Central_difference(i) = (Z(1)*exp(x-2*dx(i))*cos(x-2*dx(i))+Z(2)*exp(x-dx(i))*cos(x-dx(i))+Z(3)*exp(x)*cos(x)+Z(4)*exp(x+dx(i))*cos(x+dx(i))+Z(5)*exp(x+2*dx(i))*cos(x+2*dx(i)))/(dx(i)^2);
left_skewed_difference(i) = (Y(1)*exp(x)*cos(x)+Y(2)*exp(x-dx(i))*cos(x-dx(i))+Y(3)*exp(x-2*dx(i))*cos(x-2*dx(i))+Y(4)*exp(x-3*dx(i))*cos(x-3*dx(i))+Y(5)*exp(x-4*dx(i))*cos(x-4*dx(i))+Y(6)*exp(x-5*dx(i))*cos(x-5*dx(i)))/(dx(i)^2);
right_skewed_difference(i)= (X(1)*exp(x)*cos(x)+X(2)*exp(x+dx(i))*cos(x+dx(i))+X(3)*exp(x+2*dx(i))*cos(x+2*dx(i))+X(4)*exp(x+3*dx(i))*cos(x+3*dx(i))+X(5)*exp(x+4*dx(i))*cos(x+4*dx(i))+X(6)*exp(x+5*dx(i))*cos(x+5*dx(i)))/(dx(i)^2);

end

central_error=abs(Central_difference-Analytical_derivative);
left_error=abs(left_skewed_difference-Analytical_derivative);
right_error=abs(right_skewed_difference-Analytical_derivative);

loglog(dx,central_error,'r')
hold on
loglog(dx,left_error,'g')
hold on
loglog(dx,right_error,'k')
xlabel('dx')
ylabel('error')
legend('central error','left error','right error')

FUNCTION PROGRAM:

function [X,Y,Z] = num_discrete(A,B,C,D,E,F)

X=inv(A)*B;

Y=inv(C)*D;

Z=inv(E)*F;

end

WORKSPACE:

Plot that compares the absolute error between the above-mentioned schemes

From the plot,central difference error is higher than skewed scheme error where skewed schemes error gives approxiamate values.

Skewed scheme encloses the data of either left sided skewed scheme or right sided skewed scheme whereas central difference scheme encloses both right and left sided scheme.Central difference scheme cannot compute higher order derivative,instead skewed scheme can compute.

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.