All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective : 1.To understand the effect of occurance of errors , while selecting the numerical schemes. 2.Numerical Discretization analysis for various Numerical schemes over a range of grid (or) mesh size. NOTE : Understanding the errors for numerical analysis is very important , this leads to optimize the output…
Epuri Yoga Narasimha
updated on 30 Jan 2021
Objective :
1.To understand the effect of occurance of errors , while selecting the numerical schemes.
2.Numerical Discretization analysis for various Numerical schemes over a range of grid (or) mesh size.
NOTE :
Understanding the errors for numerical analysis is very important , this leads to optimize the output of the problem during computations.
Results explanation below..
Types of errors:
1.Inherent errors -> These errors are already included in the problem statement.
2.Truncation errors. -> These errors are due to approximating the results , like in representation of infinite series as finite(truncating).
3. Round off Errors. -> These errors are depend on the precesion of the computer. rounding off during comutation.
Let x -> True value.
x' -> Approximate value.
4. Absolute Error -> |x - x'|.
5. relative Error -> |x-x′||x||x−x'||x|
6. percentage errors. -> |x-x′||x|⋅100|x−x'||x|⋅100
Command used :
loglog -> This command is used to plot the data that difference between the data are large.
log10 -> This command is used to represent the powers of 10 , as a numeric values.
abs -> give absolute value of the computation.
1. Forward Difference Approximation.
f′=f(x+dx)-f(x)dx
2. Central Difference Approximation.
f′=f(x+dx)-f(x-dx)2⋅dx
3. Central 4th order Approximation.
f′=f(x-2⋅dx)-8⋅f(x-dx)+8⋅f(x+dx)-f(x+2⋅dx)12⋅dx
Just imagine a tangent curve at the peak of curve of red curve , that our actual study.
But we study the secent lines represented in graph.
As can observe that central difference approximation is near to the model(more accurate).
Taylor Series Expansion :
f(x)=f(a)+f′(a)1!⋅(x-a)1+f′′(a)2!⋅(x-a)2+f′′′(a)!⋅(xi+1-f(xi))3+...
For Foward Difference , put x = xi+1.
a = xi.
f(xi+1)=f(xi)+f′(xi)1!⋅(xi+1-xi)+f′′(xi)2!⋅(xi+1-xi)2+f′′′(xi)3!.(xi+1-xi)3+... --------->1
f(xi+1)-f(xi)h=f′(xi)+O(h)
For Backward Difference , put x = xi-1.
a = xi.
f(xi-1)=f(xi)-f′(xi)1!⋅(xi-1-xi)+f′′(xi)2!⋅(xi-1-xi)2-f′′′(xi)3!.(xi-1-xi)3+... ----------->2
f(xi-xi-1)h=f′(x)+O(h)
For Centeral Difference Approximation :
Subtract equation 2 from equation 1, we get
f(xi+1)-f(xi-1)=2⋅f′(xi)1!⋅(h)1+2⋅f′′′(xi)3!⋅(h)3+...
Divide by 2h on both sides
f(xi+1)-f(xi-1)(2⋅h)=f′(xi)1!+f′′′(xi)3!⋅(h)2+...
Can observe that order of Error is : O(h2)
Main Code Snippet :
%% Clearing commands
close all
clear all
clc
dx = linspace(pi/4,pi/4000,20);
x = pi/3;
for i = 1:length(dx)
[order_1a(i)] = first_order_approximation(x,dx(i));
[order_2a(i)] = second_order_approximation(x,dx(i));
[order_4a(i)] = fourth_order_approximation(x,dx(i));
end
% plotting
% loglog(X,Y) plots x- and y-coordinates using a base 10 logarithmic scale on the x-axis and the y-axis.
loglog(dx,order_1a)
hold on
loglog(dx,order_2a,'color','r')
loglog(dx,order_4a,'color','m')
xlabel('grid size on log1og scale')
ylabel('error on log1og scale')
legend('first-order-approximation','second-order-approximation','fourth-order-approximation','location','NorthWest')
figure(2)
plot(log10(dx),log10(order_1a))
hold on
plot(log10(dx),log10(order_2a))
plot(log10(dx),log10(order_4a))
xlabel('grid size on log10 scale')
ylabel('error on log10 scale')
legend('first-order-approximation','second-order-approximation','fourth-order-approximation','location','NorthWest')
grid on
Explanation :
1.At first , used clearing commands to clear the data on the present interface.
2. Declared required variables -> target value ,grid size.
3.Used functions in the for loop to get the required data from different numerical schemes.
4. For loop used to get data for all gris sizes.
5. using the data , plotted the data using loglog and log10.
6. Labeled the figure.
Explanation for all functions:
1. Structure of alll function are same.
2. function conatain 2 inputs and 1 output.
3. outputs from the function are absolute errors.
first_order_approximation code snipppet:
function out_first_order = first_order_approximation(x,dx)
%Forward_Difference_First_order_Approximation
out_first = (dis_r(x+dx) - dis_r(x))/dx;
True_value = (x^3*(cos(x)) - sin(x)*3*x^2)/(x^6);
out_first_order = abs(True_value-out_first);
end
second_order_approximation code snipppet:
function out_second_order = second_order_approximation(x,dx)
%central_Difference_First_order_Approximation
out_second = (dis_r(x+dx) - dis_r(x-dx))/(2*dx);
True_value = (x^3*(cos(x)) - sin(x)*3*x^2)/(x^6);
out_second_order = abs(True_value-out_second);
end
fourth_order_approximation code snipppet:
function out_fourth_order = fourth_order_approximation(x,dx)
%central_Difference_First_order_Approximation
out_fourth =(dis_r(x-2*dx) - 8*dis_r(x-dx) + 8*dis_r(x+dx) - dis_r(x+2*dx))/(12*dx);
True_value = (x^3*(cos(x)) - sin(x)*3*x^2)/(x^6);
out_fourth_order = abs(True_value-out_fourth);
end
RESULTS:
Figure 1 Figure 2
Figure 3
Figure 4
Explanation of results:
1. from figure 1 , observed the variation of errors with gris size reinfinement.
2. Fourth order approximation(O(h4)) are very accurate than , first(O(h)) and second order(O(h2)) approximations.
3. From the figure 2 , log10 plot, easy to calculate the slops for all schemes , using data point as show in figure.
4. In figure 3 , calculated the slopes , and can observe that the slopes are equal to the order of approximation.
5. So ,order of approximation ttells about the steepness.
6. In figure 4 , considered first order approximation 'O(h)' , observed that on decreasing the h by 10 , error also get reduced by 10 since O(h).
Note :
1. If we opt for reducing the truncation error , the error will decrease upto certain fine h value , further error increase due to round off error
Codes for understanding round off and truncation error importance:
Step size 'h':
% To calculate numerical derivative of atna(x)
close all;
clear all;
clc;
a = 1;
trueval = 1/(1+a^2);
% Calculating derivatives for step size '1'
for i = 2:7
h = 10^(-i);
approxVal = (atan(a+h) - atan(a))/h;
err = abs(trueval - approxVal);
hAll(i-1) = h;
errAll(i-1) = err;
end
%%
% Plot error vs step size
% we get a linear curve since error is order of h.
% so,if we decrease h by factor 10 , error also decrease by order 10.
loglog(hAll,errAll)
Step size 'h10' :
%% Calculating derivatives for step size '2'
for i = 2:2:14
h = 10^(-i);
approxVal = (atan(a+h) - atan(a))/h;
err = abs(trueval - approxVal);
hAll(i/2) = h;
errAll(i/2) = err;
end
loglog(hAll,errAll)
% trade off between truncation and round off errors ,while solving
% numerical derivatives.
% upto certain point the error get decreased by reducing step size(h) , and
% even by decreasing of step size(h) error get increased , this is due to
% round off errors.
% eps
% truncation , round-off , trade-off truncation and round-off errors results
%in some unique properties in numerical methods.
Step Size 'h' Step Size 'h10'
1. As can observe that , for grid size 'h' , error get reduced linearly.
2. On refining grid size 'h10' , error decreased and error increased , due to round-off errors (machine precsion).
Conclusion :
1. Analysed the errors in numerical schems , got their importance in computations.
2. Explained as per requirement.
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...
Project 4
Objective 1. Detect lanes using Hough Transform Method. Steps in lane Detection 1. Detect Edges using Canny Edge Detection Method. 2. Capture the Region of Interest in Image. 3. Detect lines using Hough Transform. 4. Calculate the actual left and right lanes from all lines. 6. Find the coordinates of the lines. 7. Display…
21 Feb 2023 05:22 AM IST
Lane Detection using Hough Transform
Objective 1. Detect lanes using Hough Transform Method. Steps in lane Detection 1. Detect Edges using Canny Edge Detection Method. 2. Capture the Region of Interest in Image. 3. Detect lines using Hough Transform. 4. Calculate the actual left and right lanes from all lines. 6. Find the coordinates of the lines. 7. Display…
21 Feb 2023 05:20 AM IST
Edge Detection and Hough Transform
Objective: Detecting Edges using Canny Edge Detector. Understand and display the outputs of all steps in the canny Edge Detection process. Effect on the output on changing the parameters of the Non-Maximum Suppression. Understand Hough Transform and Lane Detection using Hough Transform. Steps Follow in the Discussion:…
28 Dec 2022 09:58 PM IST
week 2 : Image Filtering
Objective: Apply Prewitt and Laplacian filter on the image Libraries used: Opencv Open Source computer vision library. cross-platform supported. can perform through c, c++, and python. numpy Mathematical library to work in the domain of Linear algebra, Fourier transform, and matrices. Image Filtering…
09 Jul 2022 06:36 AM 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.