Project

Discretization Basics

REPORT:

DISCRETIZATION BASICS

OBJECTIVE:

In this project the first order derivative is discretized to obtain the desired order of accuracy. It is then discretized with forward differencing scheme to compare the results.

FORMULA FOR THE FOURTH ORDER APPROXIMATION USING FIRST DERIVATIVE:

GIVEN:

function f(x) = sinx/x^3

first derivative at x=pi/3

Analytical first derivative = (x^3*cosx-3*sinx*x^3)/x^6

Assuming infinitesimal quantity, dx=pi/15

Forward and central differencing methods are used to find the numerical derivative.

First order approximation, forward differencing = [f(x+a)-f(x)]/`Delta`x

Second order approximation, central differencing =[f(x+a)-f(x-a)]/2`Delta`x

Fourth order approximation, central differencing = f(x-2a)-8*(x-a)-8*(x+a)-f(x+2a)/12`Delta`x.

MATLAB CODE:

 close all
 clear all
 clc
 
 x=pi/3;
 dx=pi/15;
 
 numerical_derivative = (x^3*cos(x)-sin(x)*3*x^2)/(x^6);
 forword_differencing = (sin(x+dx)/(x+dx)^3)-(sin(x)/(x)^3)/dx;
 first_order_error = abs(forword_differencing-numerical_derivative)
 central_differencing = (sin(x+dx)/(x+dx)^3)-(sin(x-dx)/(x-dx)^3)/(2*dx);
 second_order_error = abs(central_differencing-numerical_derivative)
 central_differencing1 = ((sin(x-2*dx)/(x-2*dx)^3)-8*(sin(x-dx)/(x-dx)^3)+8*(sin(x+dx)/(x+dx)^3)-(sin(x+2*dx)/(x+2*dx)^3))/(12*dx);
 fourth_order_error = abs(central_differencing1-numerical_derivative)
 c= categorical({'first order approx','second order approx','fourth order approx'});
 error = [first_order_error second_order_error fourth_order_error];
 bar(c,error)
 
 xlabel('order of approximations')
 ylabel('errors')
 legend('order of approximations')
 title('effect of order of derivatives against numerical errors')
         

BAR GRAPH:

RESULT:

The bar graph clearly shows that the error for the fourth order approximation is the lowest followed by the second order approximation and the first order approximation respectively.

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.