Challenge

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

first the main program consisting of the input variables :

x=pi/3;
fx=exp(x)*cos(x);
dx=linspace(pi/10,pi/100,100);
seoa=-2*exp(x)*sin(x);
for i=1:length(dx)
sllds(i)=skewed_left(x,dx(i),fx,seoa)
srrds(i)=skewed_right(x,dx(i),fx,seoa)
cdds(i)=central_difference(x,dx(i),fx,seoa)

end
plot(dx,cdds,'g',dx,sllds,'b',dx,srrds,'k')
xlabel('angle dx')
ylabel('repective error')
gtext('skew.rh.side diff error')
gtext('skew lf .s diff error')
gtext('central diff error')
legend('trauncation errors comparisions for diff numerical approximations')

then defining respective error functions:

for skewed left sided difference

function error_slds=skewed_left(x,dx,fx,seoa)
 K=[1 1 1 1 1 ;-4 -3 -2 -1 0;16/2 9/2 2 1/2 0;-64/6 -27/6 -8/6 -1/6 0;256/24 81/24 16/24 1/24 0];
 L=[0;0;1;0;0];
 M=inv(K)*L;
 slds=(M(5)*fx+M(4)*exp(x-dx)*cos(x-dx)+M(3)*exp(x-2*dx)*cos(x-2*dx)+M(2)*exp(x-3*dx)*cos(x-3*dx)+M(1)*exp(x-4*dx)*cos(x-4*dx))/(dx^2);
 error_slds=abs(slds-seoa)
end 

for skewed right side difference:

function error_slds=skewed_left(x,dx,fx,seoa)
 K=[1 1 1 1 1 ;-4 -3 -2 -1 0;16/2 9/2 2 1/2 0;-64/6 -27/6 -8/6 -1/6 0;256/24 81/24 16/24 1/24 0];
 L=[0;0;1;0;0];
 M=inv(K)*L;
 slds=(M(5)*fx+M(4)*exp(x-dx)*cos(x-dx)+M(3)*exp(x-2*dx)*cos(x-2*dx)+M(2)*exp(x-3*dx)*cos(x-3*dx)+M(1)*exp(x-4*dx)*cos(x-4*dx))/(dx^2);
 error_slds=abs(slds-seoa)
end 

for central difference:

function error_cds=central_difference(x,dx,fx,seoa)
 A=[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];
B=[0;0;1;0;0];
c=inv(A)*B;
cds=((c(1)*exp(x-dx*2)*cos(x-2*dx))+(c(2)*exp(x-dx)*cos(x-dx))+c(3)*fx+(c(4)*exp(x+dx)*cos(x+dx)+c(5)*exp(x+dx*2)*cos(x+2*dx)))/(dx^2);
error_cds=abs(seoa-cds)
end 

plot: provided below.

inference from plot:from the plot,the central difference error is less .so obviously,its the most accurate scheme.

Here we go with numerical representation of representing an differential equation in algebraic with various numerical representations.

Basically there are three types.They are:

1.central differential scheme.

2.skewed rightsided difference.

3.skewed left sided difference.

1.central differential scheme

In this,the value of second ordered derivative of a function is represented interms of the algebraic summation of the points around the initial point.we get the info chained to form a stencil containing five points.

The representation is

D^2f/dx^2*=a*f(i-2)+b*f(i-1)+c*f(i)+d*f(i+1)+e*f(i+2)/(dx^2);

Whereas the f(i-J#)is =f(i)+f’(i-j*dx)dx+f’’(i-j*dx)dx^2/2!+f’’’(i-j*dx)dx^3/3!+………………

So, upon clubbing of ordered derivatives from the above derivatives, there arises five eqns to get the values of constants a, b,….

We deploy matrix inversion method to get the values of those constants.

The so called taylor table to solve for derivative in central differencing scheme is as follows;

Fx dx*f’x dx^2*f”x dx^3*f”’x dx^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

as the net requirement on the left side is only second order differentiation,we make the coefficients of the remaining order to be zeroed.so,in this process e deploy matrix iinversion to find the coefficients.

From the table,

a+b+c+d+e=0

-2a-b+d+2e=0

4a/2+b/2+d/2+4e/2=1

-8a/16-b/6+d/6+8e/6=0

16a/24+b/24+d/24+16e/24=0

By considering auxillary eqn[AX=B] type solving for matrix X of coefficiients,

A=[1 1 1 1 1

-2 -1 0 1 2

4/2 ½ 0 ½ 4/2

-8/6 -1/6 0 1/6 8/6]

X=[a;b;c;d;e]

B=[0;0;1;0;0]

***Here,the power of dx in trancuation error is raise to two,rather than one in skewed differentiaton,which brings more approximation upon its usage.

2.skewed right sided difference:

In numerical approximation of fourth order approximations of second order derivative ,if we move with the data wholely from the succeeding points,the stencil so obtained is of skewed right side difference.

In the process of numerical approximation;

D^2f/dx^2=af(i)+bf(i+1)dx+cf(i+2)dx^2/2!+df(i+3)dx^3/3!+ef(i+4)dx^4/4!+gf(i+5)dx^6/(dx^2)

Taylor table for skewed right sided difference scheme:

f(x) f’(x)dx f‘’(x)dx^2 f’’’(x)dx^3 f’’’’(x)dx^4 f’’’’’(x)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 2c 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/24 625g/24 3125g/120

the constrain equations of the constants are:

a+b+c+d+e+g=0

b+2c+3d+4e+5g=0

b/2+2c+9d/2+16e/2+25g/2=1

b/6+8c/6+27d/6+64e/6+125g/24=0

b/24+16c/24+81d/24+256e/24+625g/24=0

b/120+32c/120+243d/120+1024e/120+3125g/120=0

solving for constants

A=[1 1 1 1 1 1;0 1 2 3 4 5;0 ½ 2 9/2 16/2 25/2;0 1/6 8/6 27/6 64/6 125 24;0 1/24 16/24 81/24 256/24 625/24;0 1/120 32/120 243/120 1024/120 3125/120]

B=[0;0;1;0;0;0]

AX=B

3.skewed left sided difference:

In numerical approximation of fourth order approximations of second order derivative ,if we move with the data wholely from the preceedinng points,the stencil so obtained is of skewed left side difference.

In the process of numerical approximation;

D^2f/dx^2=af(i)+bf(i-1)dx+cf(i-2)dx^2/2!+df(i-3)dx^3/3!+ef(i-4)dx^4/4!+gf(i-5)dx^6/(dx^2)

Taylor table for skewed right sided difference scheme:

f(x) f’(x)dx f‘’(x)dx^2 f’’’(x)dx^3 f’’’’(x)dx^4 f’’’’’(x)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 2c -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/24 625g/24 -3125g/120

the constrain equations of the constants are:

a+b+c+d+e+g=0

-b-2c-3d-4e-5g=0

b/2+2c+9d/2+16e/2+25g/2=1

-b/6-8c/6-27d/6-64e/6-125g/24=0

b/24+16c/24+81d/24+256e/24+625g/24=0

-b/120-32c/120-243d/120-1024e/120-3125g/120=0

solving for constants

A=[1 1 1 1 1 1;0 -1 -2 - 3 - 4 -5;0 ½ 2 9/2 16/2 25/2;0 -1/6 -8/6 -27/6 -64/6 -125/ 24;0 1/24 16/24 81/24 256/24 625/24;0 -1/120 -32/120 -243/120 - 1024/120 -3125/120]

B=[0;0;1;0;0;0]

AX=B

***in skewed difference schemes,interpolation and extrapolation is easy at boundary conditions.whereas for central difference scheme,we dont have data sufficient at boundary.Here's where cds will be over taken by skewed schemes.

where as error in cds is comp low and more appx the calculated values.

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.