VPA contains MATLAB programs which demonstrate the use of variable precision arithmetic.
MATLAB's variable precision arithmetic is only available through the Symbolic Math Toolbox. To find out if you have this toolbox installed, you can type "ver" within your MATLAB session.
In MATLAB, evaluating a symbolic variable means creating a representation of its value, to a given number of digits, as a floating point number. The vpa() command is used to create the floating point representation. Typical uses are:
r = vpa ( s )which takes the symbolic object s and evaluates it as a symbolic real number to the current default number of digits or
r = vpa ( s, d )which uses d digits in the real number representation.
The current default number of digits can be found by using the digits() command:
dignum = digits;or
dignum = digits ( );The default number of digits can be changed by including an input argument to the digits() command:
digits ( 50 );
To my mind, a significant issue with the symbolic math toolbox is that it is not apparent how to control the printing of the value of a given variable. If I compute something to 80 digits, I can always display it by naming it. But what if I prefer a labeled printout? Various alternatives involving "disp()" and "fprintf()" and string concatenation seem unsatisfactory.
The computer code and data files made available on this web page are distributed under the BSD license.
VPA is available in a MATLAB version.
COMPUTING_PI is a collection of three functions discussed by Cleve Moler for computing pi to many digits.
You can go up one level to the MATLAB source codes.