Can I eliminate roundoff error caused due to floating point arithmetic limit in MATLAB?
20 views (last 30 days)
Show older comments
I am trying to do an error analysis of RK4 in MATLAB. But after the step size reaches a particular value the error starts increasing with decrease in step size. I know that these occurs due to the round off error generated in MATLAB. What can be the solution of this?
2 Comments
Stephen23
on 17 Jan 2022
Edited: Stephen23
on 17 Jan 2022
"Can I eliminate roundoff error caused due to floating point arithmetic limit in MATLAB?"
The very general answer to your very general question is no.
If there was a general solution to "eliminate roundoff error caused due to floating point arithmetic" then everyone would use it.
In some circumstances you can change an algorithm to make it more numerically robust, but as you did not provide any details of the arithmetic that you are performing we cannot help you know if that can be applied to your code.
Answers (1)
Star Strider
on 17 Jan 2022
Floating-point approximation error is simply inherent in binary representations of floating-point numbers. The best way to deal with it is to use a tolerance, for example —
flag = abs(x - target) < 1E-4;
or something similar, to test for the equality of ‘x’ and ‘target’ unless all the values are integers, since in that situation exact representations and comparisons are possible. Use whatever tolerance value (here 1E-4) is appropriate.
.
3 Comments
John D'Errico
on 17 Jan 2022
@Ankhiparna Guha - You CANNOT go beyond roughly 15-16 significant digits in floating point arithmetic. So no. You cannot eliminate floating point errors when working in floating point arithmetic. At best you can use good numerical practices, the things taught in numerical analysis and numerical methods courses, to avoid issues. These are the kinds of things I assume you will learn in the classes you are taking, since you are trying to solve this problem. One such idea is to use tolerances, as Star suggests. As for what is exactly happening in your code, we cannot know, since we see no code from you, nor any idea what exactly you did.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!