Precision arithmetic

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?

 Réponse acceptée

Walter Roberson
Walter Roberson le 23 Mar 2011

0 votes

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.

2 commentaires

Tarapun
Tarapun le 23 Mar 2011
Thank you, for your answer. Is there another alternative for function vpa?
Walter Roberson
Walter Roberson le 23 Mar 2011
No, not for your purpose. All MuPad internal arithmetic is defined in terms of significant digits, not in terms of number of decimal places.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by