All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective : To write a program that compares the first, second and fourth order approximations of the first derivative against the analytical or exact derivative and calculates the error as absolute difference of the approximations against exact / analytical derivative . Report : The function `f(x)…
Aadil Shaikh
updated on 22 Jan 2020
clear all
close all
clc
%analytical funtion = sin(x)/x^3;
% analytical derivative
% f'(x) = (x^3(cos(x))-sin(x)*3*x^2)/x^6;
x = pi/3;
dx = pi/18;
% first order error function
first_order_error = first_order_approx(x,dx) ;
% second order error function
second_order_error = second_order_approx(x,dx) ;
% fourth order error function
fourth_order_error = fourth_order_approx(x,dx) ;
% naming the x side of the bar graph
x = categorical({'1st.order','2nd.order','4th.order'});
% y side plotting order and terms to plot
y = [ first_order_error ; second_order_error; fourth_order_error ];
bar(x,y)
title('Absolute error from approximations of 1st,2nd & 4th order')
grid on
xlabel('Approximations');
ylabel('Absolute error');
saveas(gcf,'Basics','png')
function output = first_order_approx(x,dx)
analytical_derivative = (x^3*(cos(x))-sin(x)*3*x^2)/x^6;
% forward differencing = (f(x+dx) - f(x))/dx
% first order approximation
first_order_approximation = (sin(x+dx)/(x+dx)^3 - sin(x)/x^3)/dx ;
output = abs(first_order_approximation - analytical_derivative);
end
function output = second_order_approx(x,dx)
analytical_derivative = (x^3*(cos(x))-sin(x)*3*x^2)/x^6;
% second order approximation
second_order_approximation = (sin(x+dx)/(x+dx)^3 - sin(x-dx)/(x-dx)^3)/(2*dx);
%error term
output = abs(second_order_approximation - analytical_derivative);
end
function output = fourth_order_approx(x,dx)
analytical_derivative = (x^3*(cos(x))-sin(x)*3*x^2)/x^6;
%fourth order approximation
fouth_order_approximation = ((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 term
output = abs(fouth_order_approximation - analytical_derivative);
end
THE END
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...
Flow over a Throttle body - Using CONVERGE CFD
I. Introduction: In this Project, A Steady & Transient state simulation is done of a Flow through an Elbow joint consisting of a throttle valve. The steady state case is solved with the Throttle valve fully open until convergence is reached. While the Transient case is ran with the throttle valve rotating i.e…
18 Sep 2020 08:29 PM IST
Literature review – RANS Derivation and analysis
Introduction: The Reynolds-averaged Navier–Stokes equations (or RANS equations) are time-averaged equations of motion for fluid flow. The idea behind the equations is Reynolds decomposition, whereby an instantaneous quantity is decomposed into its time-averaged and fluctuating quantities,…
18 Sep 2020 08:28 PM IST
C.H.T Analysis on a Graphic card using ANSYS FLUENT
I. Introduction : In this project, A steady state conjugate heat transfer analysis on a Graphic card model is done. Graphic card has become an everyday used object and a very importat part of any computer system, laptops etc. This product is mass produced daily in millions and has made computers exceptionally efficient.…
18 Sep 2020 08:23 PM IST
Aerodynamics : Flow around the Ahmed Body using ANSYS FLUENT
I. Introduction : Automotive aerodynamics comprises of the study of aerodynamics of road vehicles. Its main goals are reducing drag, minimizing noise emission, improving fuel economy, preventing undesired lift forces and minimising other causes of aerodynamic instability at high speeds. Also, in order to maintain…
18 Sep 2020 08:21 PM IST
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.