Project

Deriving the forth order approximation of the 2nd order derivative

Objective:

The objective here is to derive the forth order approximation of the Skewed right hand side scheme and the central difference scheme using Taylors table and making sure that the stencil that we use is of forth order approximation.

Numerical derivative to be decritized:

`(del^2f)/(delx^2)` --------------------------- Let this be equation (1)`

stencil to be used for the forth order approximation for skewed right hand side scheme:

Based on the stencil the equation can be written as

`(del^2f)/(delx^2) approx`af(i) + bf(i+1) +cf(i+2) + df(i+3) + ef(i+4) + hf(i+5`

Using the Taylor's Table method to find out the co-efficients of a,b,c,d,e,h

we have 6 unknows and hece forth we need 6 equations. from the taylors table the equation formed from the f''(x) can be assumed to be one as we need the approximation for the 2nd order derivative. the rest all equations except the f^VI(x) can be assumed to be zero.

Thus the equations created are

a + b + c + d + e + h = 0;

b + 2*c + 3*d + 4*e + 5*h = 0

b/2 + 2*c + 3^2*d/2 + 4^2*e/2 + 5^2*h/2 = 1

b/6 + 2^3*c/6 + 3^3*d/6 + 4^3*e/6 + 5^3*h/6 = 0

b/24 + 2^4*c/24 + 3^4*d/24 + 4^4*e/24 + 5^4*h/24 = 0

b/120 + 2^5*c/120 + 3^5*d/120 + 4^5*e/120 + 5^5*h/120 = 0``

Solving all the equations we get

a = 3.75

b = -12.83

c = 17.83

d = -13

e = 5.083

h = -0.8333

`(del^2f)/(delx^2) approx af(i) + bf(i+1) + cf(i+2) + df(i+3) + ef(i+4) + hf(i+5) = trianglex^2*f''(x) + (b/720 + 2^6*c/720 + 3^6*d/720 + 4^6*e/720 + 5^6*h/720)*f^(VI)(x)*trianglex^6`

Let this be equation 2

This equation further gets reduced to

`(del^2f)/(delx^2) approx af(i) + bf(i+1) + cf(i+2) + df(i+3) + ef(i+4) + hf(i+5) = trianglex^2*f''(x) + O*trianglex^6`

Let this be equation 3

Taking `trianglex^2` common from the R.H.S of equation 3 we get

`(af(i) + bf(i+1) + cf(i+2) + df(i+3) + ef(i+4) + hf(i+5))/ (triangle x^2) = f''(x) + O*trianglex^4`

The term `O*trianglex^4` denotes the truncation error and the order of approximation. Hence forth the derived equation is of 4th order for the 2nd derivative.

consistency check by evaluating the above equation for `e^x`

The 2nd derivative for `e^x`is also `e^x`, now writing a code in matlab to solve the equation from different values of dx we achieve the following plot. The snippet of the code loop is shown below.

This is the loop used to calculate the numerical derivative at different time steps

for i = 1:length(Dx)
    dx = (Dx(i));
    Numerical_derivative(i) = (a*exp(x) + b*exp(x+dx) + c*exp(x+(2*dx)) + d*exp(x+(3*dx)) + e*exp(x+(4*dx)) + h*exp(x+(5*dx)))/dx^2;
    Analytical_derivative(i) = exp(x);
    error(i) = abs(Numerical_derivative(i)-Analytical_derivative(i))
end

The result is plotted using a loglog plot and the plot shows that the scheme is consistent.

This shows for lower value of dx the error value is also low, but when the value of dx becomes too small we start to face the round off error.

Now in this case we can see that, for very low values of dx the system rounds off the value and hence forth this causes an error in the system so as the dx goes low after a particular minimum value of dx we can see that the error starts to increase.

Deriving the Central difference scheme of forth order approximation of the 2nd order derivative:

Let us 1st define the stencil that is to be used

`(del^2f)/(delx^2) approx af(i-2) + bf(i-1) + cf(i) + df(i+1) + ef(i+2)`

Using the taylor's table method

a + b + c + d + e = 0

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

2^2*a/2 + b/2 + d/2 + 2^2*e/2 = 1

2^3*a/6 + b/6 + d/6 + 2^3*e/6 = 0

2^4*a/24 + b/24 + d/24 + 2^4*e/24 = 0

-2^5*a/120 -b/120+d/120+2^5*e/120 = ?----------------------------------------(I)

Let us now find the co-efficients

a = -0.0833

b = 1.33

c = -2.5

d = 1.33

e = -0.0833

substituting the values in (I) the equation become zero, so

`(del^2f)/(delx^2) approx af(i-2) + bf(i-1) + cf(i) + df(i+1) + ef(i+2) = f''(x)trianglex^2 + (2^6*a/720+b/720+d/720+2^6*e/720)*f^(VI)(i)*trianglex^6`

rewriting the order term and taking `trianglex^2` common from the R.H.S we get

`(del^2f)/(delx^2) approx (af(i-2) + bf(i-1) + cf(i) + df(i+1) + ef(i+2))/(trianglex^2) = f''(x) + O*trianglex^4`

Now the truncation error term denotes that the order of the approximation is 4th order.

Checking for consistency of the scheme:

solving the above scheme we can see that the value of error decreases with decrease in dx. the plot shows something like this.

On further decreasing the value of dx we can see that the roundoff error again starts to show and the plot become like this.

You can see for the given function the roundoff error starts to showup as dx is reduced.

conclusion:

Thus we have sucessfuly derived the 4th order approximation for the 2nd derivative and also checked for its consistency.

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.