Changing numerical precision for math operations
8 views (last 30 days)
Show older comments
I wonder how to change numerical precision of MatLab for those processes that require it. MatLab works with 16 digits at default and I know there is a VPA and DIGITS option to change it --more info in the link and link-- but not sure of how it works actually and they both require the Symbolic Math Toolbox (which I don't have yet).
If I change the precision of one numer, all operations with it will automatically match the precision? Matchs the higher one, the lower one? I have to change it for all number in a program and for all their operations?
PS: How and where can I obtain that extenssion?
0 Comments
Answers (1)
John D'Errico
on 12 Apr 2022
Edited: John D'Errico
on 12 Apr 2022
You have TWO choices for floating point precision, double or single.
A = double(1);
B = single(2);
C = A + B
class(C)
Arithmetic operations like this will be cast to the lower precision.
You CANNOT tell MATLAB to automatically work in single precision, except by creating variables that are singles. Even there, be careful though, because many operations might create doubles. However, it does not sound as if you want lower precision, but higher. And you cannot get a higher precision without some other tool.
You will not be happy with doing all of your computations using symbolic tools, as now your code will become incredibly slow.
How do you get the symbolic toolbox? You buy it. Or you can download my HPF toolbox from the file exchange, but it has the same issues in terms of being slow. At least HPF is free.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!