All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
DETAILED REPORT ON DISCRETIZATION BASICS FOR A RANGE OF dx 1. AIM To write a program that compares the first, second and fourth order approximations of the given function f(x) = sin(x)/x^3 for a range of dx against the analytical derivative. EQUATIONS/ FORMULAE USED Given function, f(x) = sin(x)/x^3…
Ramkumar Venkatachalam
updated on 29 Jan 2022
DETAILED REPORT ON DISCRETIZATION BASICS FOR A RANGE OF dx
1. AIM
To write a program that compares the first, second and fourth order approximations of the given function f(x) = sin(x)/x^3 for a range of dx against the analytical derivative.
Given function, f(x) = sin(x)/x^3
Analytical derivative, f'(x) = (xcos(x) - 3sin(x))/x^4, x=pi/3 is the point of consideration where the function is being solved and dx ranges from pi/4000 to pi/40 with 200 interval points.
Basically, Taylor series is used here for numerical approximation. Two types of differencing scheme are used such as forward and central differencing scheme.
Forward differencing scheme
It’s a scheme in which the derivative is calculated using the information from the point on right side of the point of consideration. Also for 1stOrder Forward differencing approximation the value is taken only from only one point.
1stOrder approx - Forward differencing scheme = (f(x+dx)-f(x))/dx
Central differencing scheme
It’s a scheme in which the derivative is calculated using the information from the very next pointon both sides (2 points) of the point of consideration. It is always used forapproximation of even number order. So for 2nd and 4thOrder Central differencing approximation the value is taken fromthe point on both sides (2 points) and two points on both sides (4 points) respectively.
2nd Orderapprox - Central differencing scheme = (f(x+dx)-f(x-dx))/dx
4th Orderapprox - Central differencing scheme = (f(x-2*dx)-(8*f(x-dx))+(8*f(x+dx))-f(x+2*dx))/(12*dx)
Error is equal to the difference in numerical and analytical derivative.
Programming language used – Octave 5.1.1
Program
-------------------------------------------------------------------------------------
MAIN PROGRAM
-------------------------------------------------------------------------------------
x = pi/3;
dx = linspace(pi/4000,pi/40,200);
for i = 1:length(dx)
first_order_error(i) = First_Order_Discretization_Basics(x,dx(i));
second_order_error(i) = Second_Order_Discretization_Basics(x,dx(i));
fourth_order_error(i) = Fourth_Order_Discretization_Basics(x,dx(i));
end
figure(1)
loglog(dx,first_order_error,'*')
hold on
loglog(dx,second_order_error,'*')
hold on
loglog(dx,fourth_order_error,'*')
xlabel('dx','Fontsize',18)
ylabel('error','Fontsize',18)
legend('first order error','second order error','fourth order error')
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
FUNCTION PROGRAM
-------------------------------------------------------------------------------------
FIRST ORDER DISCRETIZATION
function out = First_Order_Discretization_Basics(x,dx)
% Given function f(x)= sin(x)/x^3;
% Analytical derivative for the given function f'(x) = (xcos(x)- 3sin(x))/x^4;
% Computing Analytical derivative at x = pi/3;
Analytical_derivative = ((x*cos(x))- (3*sin(x)))/x^4;
% Numerical Derivative
% 1st Order approx - Forward differencing scheme = (f(x+dx)-f(x))/dx;
Forward_differencing_scheme = ((sin(x+dx)/(x+dx)^3)-(sin(x)/x^3))/dx;
% First Order Error
out = abs (Analytical_derivative - Forward_differencing_scheme);
end
-------------------------------------------------------------------------------------
SECOND ORDER DISCRETIZATION
function out = Second_Order_Discretization_Basics(x,dx)
% Given function f(x)= sin(x)/x^3;
% Analytical derivative for the given function f'(x) = (xcos(x)- 3sin(x))/x^4;
% Computing Analytical derivative at x = pi/3;
Analytical_derivative = ((x*cos(x))- (3*sin(x)))/x^4;
% Numerical Derivative
% 2nd Order approx - Central differencing scheme = (f(x+dx)-f(x-dx))/dx;
Central_differencing_scheme = ((sin(x+dx)/(x+dx)^3)-(sin(x-dx)/(x-dx)^3))/(2*dx);
% Second Order Error
out = abs (Analytical_derivative - Central_differencing_scheme);
end
-------------------------------------------------------------------------------------
FOURTH ORDER DISCRETIZATION
function out = Fourth_Order_Discretization_Basics(x,dx)
% Given function f(x)= sin(x)/x^3;
% Analytical derivative for the given function f'(x) = (xcos(x)- 3sin(x))/x^4;
% Computing Analytical derivative at x = pi/3;
Analytical_derivative = ((x*cos(x))- (3*sin(x)))/x^4;
% Numerical Derivative
% 4th Order approx - Central differencing scheme = (f(x-2*dx)-(8*f(x-dx))+(8*f(x+dx))-f(x+2*dx))/(12*dx);
Fourth_Order_Central_differencing_scheme = ((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
out = abs (Analytical_derivative - Fourth_Order_Central_differencing_scheme);
end
5. RESULTS
Graph
6. CONCLUSION
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.