MATLAB: How to perform computations in any user-defined precision and not just double precision in MATLAB

customextendedprecisionSymbolic Math Toolboxuser-defined

Can I use MATLAB to perform computations in any user-defined precision and not just double precision?
I want to compute using different precision, like 50 digits or quadruple precision. Can I do this in MATLAB?

Best Answer

MATLAB can perform computations with the desired level of precision if you use variable precision arithmetic. This requires the use of Symbolic Math Toolbox. If you have the Symbolic Math Toolbox, then you may use the MuPAD Kernel to perform computations to desired precision.
For example:
To display the value of 'pi', the default double precision display in MATLAB is:
pi
ans =
3.14159265358979
You can use the VPA (Variable Precision Arithmetic) function from the Symbolic Math Toolbox to display the value of 'pi' to as many significant digits as you want. This is shown below for 25 digits:
vpa('pi', 25)
ans =
3.141592653589793238462643
For additional information and examples using VPA please execute:
>> doc vpa
at the MATLAB command prompt.
In the absence of the symbolic math toolbox you can use the following data types to obtain different degrees of precision:
1. single
2. double
3. unit8
4. uint16
5. uint32