All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective:- 1. For a range of dx, plot the first order, second and fourth order error. 2. Make sure that you plot dx vs error in a way that makes sense. 3. Explain the results in the space provided. What can you say about the slope of the curves in this plot? Formula for the fourth order approximation of the first derivative.…
Mohammad Saifuddin
updated on 08 Aug 2019
Objective:-
1. For a range of dx, plot the first order, second and fourth order error.
2. Make sure that you plot dx vs error in a way that makes sense.
3. Explain the results in the space provided. What can you say about the slope of the curves in this plot?
Formula for the fourth order approximation of the first derivative.
Software used:- MATLAB
Solution:-
Matlab code for relation between range of dx and first order, second and fourth order error.
clear all
close all
clc
% analytical function f(x) = sin(x)/x^3
x = pi/3;
dx = linspace(0,1,20000); % range of dx
f = sin(x)/x^3;
% for loop for calculating the values of error of the range of error
for i = 1:length(dx)
first_order_error(i) = first_order(x,dx(i)); % calling the function for calculating 1st order error
second_order_error(i) = second_order(x,dx(i)); % calling the function for calculating 2nd order error
fourth_order_error(i) = fourth_order(x,dx(i)); % calling the function for calculating 4th order error
end
% plotting all the figures
figure(1);
plot(dx,first_order_error,'color','r','linewidth',2);
xlabel('dx');
ylabel('error');
legend('1st order error','location','northwest');
title('Error between analytical derivative and 1st order approximation')
figure(2)
plot(dx,second_order_error,'color','b','linewidth',2);
xlabel('dx');
ylabel('error');
legend('2nd order error','location','northwest');
title('Error between analytical derivative and 2nd order approximation')
figure(3);
plot(dx,fourth_order_error,'color','g','linewidth',2);
xlabel('dx');
ylabel('error');
legend('4th order error','location','northwest');
title('Error between analytical derivative and 4th order approximation')
% plotting the graph on log scale so that relation between dx and error can
% be easily visualized
figure(4)
loglog(dx,first_order_error,'color','r','linewidth',2);
hold on;
loglog(dx,second_order_error,'color','b','linewidth',2);
hold on;
loglog(dx,fourth_order_error,'color','g','linewidth',2);
xlabel('dx');
ylabel('error');
legend('1st order error','2nd order error','4th order error','location','northwest');
title('Error between analytical derivative and 1st order, 2nd order and 4th order approximation')
Matlab code for Function to calculate the 1st order approximation error
function out = first_order(x,dx)
analytical_sol = cos(x)/x^3 - (3*sin(x))/x^4;
numerical_sol = ((sin(x+dx)/(x+dx)^3) -( sin(x)/(x)^3))/(dx);
out = abs(analytical_sol - numerical_sol); % out is giving the absolute error value
end
Matlab code for Function to calculate the 2nd order approximation error
function out = second_order(x,dx)
analytical_sol = cos(x)/x^3 - (3*sin(x))/x^4;
numerical_sol = ((sin(x+dx)/(x+dx)^3) - (sin(x-dx)/(x-dx)^3))/(2*dx);
out = abs(analytical_sol - numerical_sol); % out is giving the absolute error value
end
Matlab code for Function to calculate the 4th order approximation error
function out = fourth_order(x,dx)
analytical_sol = cos(x)/x^3 - (3*sin(x))/x^4;
numerical_sol = ((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);
out = abs(analytical_sol - numerical_sol); % out is giving the absolute error value
end
Report:
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...
External Aerodynamics of a Mercedes Truck After Performing Surface Wrapping in STAR-CCM+
Surface Wrapping Surface wrapping is a method of extracting the desired surface with the desired volume of interest to perform CFD analysis. Surface wrapping does not incorporate all the minor details of the inside of the geometry, it only takes the outer detail of the geometry. When the CAD file contains a lot…
16 Feb 2020 02:12 PM IST
External flow Analysis of Ahmed body and Comparing the Numerical and Experimental data in STAR-CCM+.
Objective: Create the Ahmed Body slant for both 250 and 350 Run Steady-state implicit coupled flow simulation Use the turbulence models K-OmegsSST and k-epsilon Validate the velocity profile along the Ahmed body at different points with the experimental data. Calculate the cd and cl using the different turbulence.…
16 Feb 2020 01:45 PM IST
External flow analysis of NACA 0012 airfoil for different values of angle of attack in STAR - CCM+
NACA The NACA airfoils are airfoil shapes for aircraft wings developed by the National Advisory Committee for Aeronautics (NACA). The shape of the NACA airfoils is described using a series of digits following the word "NACA". The parameters in the numerical code can be entered into equations to precisely generate the cross-section…
29 Jan 2020 04:34 AM IST
Transient state analysis of Rayleigh Taylor instability in ANSYS FLUENT.
Objective Discuss some practical CFD models that have been based on the mathematical analysis of Rayleigh Taylor waves. And explain how these mathematical models have been adapted for CFD calculations. Perform the Rayleigh Taylor instability simulation for 3 different mesh sizes with the base mesh being 0.5 mm. Compare…
15 Jan 2020 09:52 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.