Challenge

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

AIM: -

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

<!-- [if !supportLists]-->1.       <!--[endif]-->Central difference

<!-- [if !supportLists]-->2.       <!--[endif]-->Skewed right-sided difference

<!-- [if !supportLists]-->3.       <!--[endif]-->Skewed left-sided difference

Also, prove that your skewed schemes are fourth-order accurate.

Write a 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.

<!-- [if !supportLists]-->1.       <!--[endif]-->Provide a plot that compares the absolute error between the above-mentioned schemes.

<!-- [if !supportLists]-->2.       <!--[endif]-->Describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot do?

 

Derivation of the 4th order approximation of the Second-Order Derivative

1)Using the Central Difference method: 

NO OF NODES:

The number of nodes = p+q-1

Where, p is order of derivative.

q is order of approximations.

The no of nodes = 2+4-1 =>5.

To derive a fourth order approximation for the second order derivative, we start with this approximation,

taylor series derivation for the above terms,

Similarly expand all the terms in the equation (1) and are represented in the form of table using taylor table method.

the linear equation obtained from the above table are solved using matrix inversion method,

A.X = B

X = inv(A)*B

we get the coefficients as,

 a=-0.0833,

b=1.3333,

c=-2.5000,

d=1.3333,

e=-0.0833

substituting this coefficient in equation (2)

SKEWED LEFT 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.

To derive a fourth order approximation for the second order derivative, we start with this approximation,

 expand all the terms in the equation (3) using taylor series expansion and are represented in the form of table using taylor table method.

the linear equation obtained from the above table are solved using matrix inversion method,

A.X = B

X = inv(A)*B

we get the coefficients as,

a=-0.8333,

b=5.0833,

c=-13.0000,

d=17.8333,

e=-12.8333,

g=3.7500

substituting this coefficient in equation (3)

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 this approximation,

expand all the terms in the equation (2) using taylor series expansion and are represented in the form of table using taylor table method.   

the linear equation obtained from the above table are solved using matrix inversion method,

A.X = B

X = inv(A)*B

we get the coefficients as,

a=3.7500,

b=-12.8333,

c=17.8333,

d=-13.0000,

e=5.0833,

g=-0.8333

substituting this coefficient in equation (2)

MATLAB CODE:

FUNCTION CODE FOR CENTRAL DIFFERENCING:

% Creating function for the 4th order approximation of the second-order; derivative using central difference;

 

function error_central_differencing = central_difference(x,dx)

 

% Analytical function f(x) = exp(x)*cos(x);

% f''(x) = -2*exp(x)*sin(x);

 

analytical_derivative = -2*exp(x)*sin(x);

 

% values of coefficients calculated from our Taylor table;

 

a=-0.083333;

b=1.333333;

c=-2.500000;

d=1.333333;

e=-0.083333;

 

% numerical derivative;

�ntral differencing =

% ((a*f(x-2*dx))+(b*f(x-dx))+(c*f(x))+(d*f(x+dx))+(e*f(x+2*dx)))/dx^2;

�ntral difference fourth order approximation;

 

central_differencing_fourth_order_approx = ((a*exp(x-2*dx)*cos(x-2*dx))+(b*exp(x-dx)*cos(x-dx))+(c*exp(x)*cos(x))+(d*exp(x+dx)*cos(x+dx))+(e*exp(x+2*dx)*cos(x+2*dx)))/dx^2;

 

error_central_differencing = abs(central_differencing_fourth_order_approx-analytical_derivative);

 FUNCTION CODE FOR SKEWED RIGHT SIDED DIFFERENCE:

% Creating function for the 4th order approximation of the second-order derivative using skewed right-sided difference;

 

function error_skewed_right_sided=skewed_right_sided(x,dx)

 

% analytical function f(x)=exp(x)*cos(x);

%f''(x)=-2*exp(x)*sin(x);

 

analytical_derivative=-2*exp(x)*sin(x);

 

%values of coefficients calculated from our Taylor table;

 

a=3.75000;

b=-12.83333;

c=17.83333;

d=-13.00000;

e=5.08333;

g=-0.83333;

 

%numerical derivative;

%skewed right-sided differencing=((a*f(x))+(b*f(x+dx))+(c*f(x+2*dx))+(d*f(x+3*dx))+(e*f(x+4*dx))+(g*f(x+5*dx)))/dx^2;

%skewed right-sided fourth order approximation;

 

skewed_right_sided_fourth_order_approx=((a*exp(x)*cos(x))+(b*exp(x+dx)*cos(x+dx))+(c*exp(x+2*dx)*cos(x+2*dx))+(d*exp(x+3*dx)*cos(x+3*dx))+(e*exp(x+4*dx)*cos(x+4*dx))+(g*exp(x+5*dx)*cos(x+5*dx)))/dx^2;

 

error_skewed_right_sided=abs(skewed_right_sided_fourth_order_approx-analytical_derivative);

end

FUNCTION CODE FOR SKEWED LEFT SIDED DIFFERENCE:

% Creating function for the 4th order approximation of the second-order derivative using skewed left-sided difference;

 

function error_skewed_left_sided=skewed_left_sided(x,dx)

 

% analytical function f(x)=exp(x)*cos(x);

%f''(x)=-2*exp(x)*sin(x);

 

analytical_derivative=-2*exp(x)*sin(x);

 

%values of coefficients calculated from our Taylor table;

 

a=-0.83333;

b=5.08333;

c=-13.00000;

d=17.83333;

e=-12.83333;

g=3.75000;

 

%numerical derivative;

%skewed left-sided differencing=((a*f(x-5*dx))+(b*f(x-4*dx))+(c*f(x-3*dx))+(d*f(x-2*dx))+(e*f(x-dx))+(g*f(x)))/dx^2;

%skewed left-sided fourth order approximation;

 

skewed_left_sided_fourth_order_approx=((a*exp(x-5*dx)*cos(x-5*dx))+(b*exp(x-4*dx)*cos(x-4*dx))+(c*exp(x-3*dx)*cos(x-3*dx))+(d*exp(x-2*dx)*cos(x-2*dx))+(e*exp(x-dx)*cos(x-dx))+(g*exp(x)*cos(x)))/dx^2;

 

error_skewed_left_sided=abs(skewed_left_sided_fourth_order_approx-analytical_derivative);

end

OUTPUT: -

Plot that compares the absolute error between the above-mentioned 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.