MATLAB: Precision arithmetic

MATLABprecision

I calculate Lyapunov Exponent. I need a big precision, such as 10000. I create a simple example for verifing calculating: >> vpa(pi, 10) ans = 3.141592654 >> vpa(pi*10, 10) ans = 31.41592654
But, I need a 10 symbols after dot. But not 9 and 8 as in example. How can I achive a calculating with specified symbols after dot?

Best Answer

Increase the vpa digits much beyond what you need and do the calculations. floor() the result, abs() it, add 1, and take ceil() of the log10 of that. The result of ceil() will be the number of digits that were used before the decimal point. With that number in hand, you can vpa() the result of the calculation, this time specifying 10 + the number of digits before the decimal point as your precision. The result will be a symbolic number.
OR....
Do the calculation with more digits than you need. char() the result of the vpa. locate the '.' in the string and discard everything after the 10th character after the decimal place. The result will be a character string.
Related Question