All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Problem Description 1. The function that needs to be computed, if f(x) = sin(x)/x^3 2. You will compute the first derivative at x = pi/3 for dx = pi/30. 2a. You will compute the derivative both numerically and analytically. Make sure you compute 1st, 2nd, and 4th order approximations. 3. Define an error parameter as the…
Pratik Ghosh
updated on 19 Jan 2021
Problem Description
1. The function that needs to be computed, if f(x) = sin(x)/x^3
2. You will compute the first derivative at x = pi/3 for dx = pi/30.
2a. You will compute the derivative both numerically and analytically. Make sure you compute 1st, 2nd, and 4th order approximations.
3. Define an error parameter as the absolute difference in numerical and exact derivative at x = pi/3
4. Plot a bar graph that shows the error
5. You need to have appropriate labels and legends on your plot
6. Make sure you upload your file
The formula for the fourth-order approximation of the first derivative
MATLAB/Octave Code:-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------
clear all
close all
clc
% [Analytical Function] = sin(x)/x^3
% [Analytical Derivative] = f'(x) = (x^3*(cos(x))-sin(x)*3*(x^2))/(x^6)
x = pi/3;
dx = pi/30;
analytical_derv = (x^3*(cos(x)) - sin(x)*3*(x^2))/(x^6);
% First order approximation, Forward Differencing
forward_diff = ((sin(x+dx)/(x+dx)^3) - (sin(x)/(x)^3))/dx
%Second order approximation, Central Differencing
central_diff = ((sin(x+dx)/(x+dx)^3) - (sin(x-dx)/(x-dx)^3))/(2*dx)
%Fourth order approximation
fourth_order_diff = ((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)
%errors
error_first_order = abs(forward_diff - analytical_derv);
error_second_order = abs(central_diff - analytical_derv);
error_fourth_order = abs(fourth_order_diff - analytical_derv);
%bar graph plotting
error = [error_first_order, error_second_order, error_fourth_order];
bar (error, 0.3)
xlabel ('Order of Approximation')
ylabel ('Truncation Error')
legend ('Order of Derivative Approximation Errors')
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bar Graph Plot :-
Conclusion:- The bar graph clearly shows that the truncation errors generated for the fourth-order approximation are the lowest which is then followed by the second-order approximation & then first-order approximations. This indicates that first-order approximations are the least accurate since containing large errors.
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...
Visualize 2D Flow Simulation Through A Backward Facing Step For 3 Distinct Mesh Grid Size Using openFOAM & ParaView
Abstract:- The work is focused on simulating fluid flow through a backward-facing step channel that would be subjected to a sudden increase in the cross-sectional area, this would result in flow separation & reattachment zones. The geometry will be designed by creating vertices & then joining them to form blocks.…
19 Jan 2021 06:26 AM IST
Week 12 - Symmetry vs Wedge vs HP equation
Objective:- The work is focused on performing a CFD simulation for a flow through a cylindrical pipe with reference to Hagen Poiseuille's principle that refers to the laminar flow formation inside a smooth cylindrical tube. Since the computation will be carried out on a laptop, we will not be able to consider the entire…
19 Jan 2021 06:26 AM IST
Writing A MATLAB/Octave Code To Perform A 1D Super-Sonic Nozzle Flow Simulation Using Macormack Method.
Abstract:- The work is focused on writing a MATLAB/Octave code to simulate the isentropic flow through a quasi 1D supersonic nozzle using both the conservation and non-conservation forms of the governing equations and solving them using MacCormack's technique and compare their solutions by performing a grid dependency…
19 Jan 2021 06:24 AM IST
Writing A MATLAB/Octave Program To Solve the 2D Heat Conduction Equation For Both Steady & Transient State Using Jacobi, Gauss-Seidel & Successive Over Relaxation (SOR) Schemes.
Problem Statement:- 1. Steady-state analysis & Transient State Analysis Solve the 2D heat conduction equation by using the point iterative techniques that were taught in the class. The Boundary conditions for the problem are as follows; Top Boundary = 600 K Bottom Boundary = 900 K Left Boundary = 400 K Right Boundary…
19 Jan 2021 06:23 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.