Changing numerical precision for math operations

8 visualizaciones (últimos 30 días)
David Román
David Román el 12 de Abr. de 2022
Editada: John D'Errico el 12 de Abr. de 2022
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?

Respuestas (1)

John D'Errico
John D'Errico el 12 de Abr. de 2022
Editada: John D'Errico el 12 de Abr. de 2022
You have TWO choices for floating point precision, double or single.
A = double(1);
B = single(2);
C = A + B
C = single 3
class(C)
ans = 'single'
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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by