Project

Comparing First, Second and Fourth Order Approximations of First Derivative against Analytical Derivative

First Order Error Function:

function Error_First_order_der=frst_order(x,dx)

Analytical_der=((cos(x))/x^3)-((3*sin(x))/x^4);

Numerical_First_order_der= ((sin(x+dx)/(x+dx)^3)-(sin(x)/x^3))/dx;

Error_First_order_der=abs(Numerical_First_order_der-Analytical_der);

end

Second Order Error Function:

function Error_Second_order_der=scnd_order(x,dx)

Analytical_der=((cos(x))/x^3)-((3*sin(x))/x^4);

Numerical_Second_order_der= ((sin(x+dx)/(x+dx)^3)-(sin(x-dx)/(x-dx)^3))/(2*dx);

Error_Second_order_der=abs(Numerical_Second_order_der-Analytical_der);

end

Fourth Order Error Function:

function Error_Fourth_order_der=frth_order(x,dx)

Analytical_der=((cos(x))/x^3)-((3*sin(x))/x^4);

Numerical_Fourth_order_der= ((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);

Error_Fourth_order_der=abs(Numerical_Fourth_order_der-Analytical_der);

end

Main Program to plot Bar Graph:

close all
clear all
clc

% Inputs %

x=pi/3;
func=sin(x)/x^3;
dx=pi/15;

% Calling the Functions %

First_order_Error=frst_order(x,dx);
Second_order_Error=scnd_order(x,dx);
Fourth_order_Error=frth_order(x,dx);

Errors=[First_order_Error,Second_order_Error,Fourth_order_Error]

% Plotting the Bar Graph %

width=dx;
Er={'First Order Approx';'Second Order Approx';'Fourth Order Approx'};

bar(Errors,width,'r')
set(gca,'xticklabel',Er)
ylabel('Errors')
legend('Approximate Errors')
title('Bar graph of different order Errors')

Bar Graph:

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.