# why does it change the number when using VPA?

3 vues (au cours des 30 derniers jours)
roey le 11 Juil 2024
Modifié(e) : Stephen23 le 11 Juil 2024
why does it change the number? let alone that its not 100 digits.
clear all
s=vpa(1.316074012952492460819218901796999055160068590205822176731922658595866795197302133050743150246601931520047742334253421353091380742095,100)
s =
1.316074012952492378047963939025066792964935302734375
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Stephen23 le 11 Juil 2024
Modifié(e) : Stephen23 le 11 Juil 2024
"why does it change the number when using VPA?"
It doesn't. That "loss of digits" is completely unrelated to VPA.
The change of digits occurs because you are using a double numeric. All double numeric values are limited to around 16 digits of precision, regardless of how many digits you write. So your code is equivalent to this:
n = define some numeric value with around 16 digits of precision
s = vpa(n)
As you can see, VPA never even gets those 100+ digits, so it certainly can't display them!
The correct approach is to avoid using an intermediate double numeric, e.g.:
s = vpa('1.316074012952492460819218901796999055160068590205822176731922658595866795197302133050743150246601931520047742334253421353091380742095',100)
s =
1.316074012952492460819218901796999055160068590205822176731922658595866795197302133050743150246601932
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Numbers and Precision dans Help Center et File Exchange

R2024a

### Community Treasure Hunt

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

Start Hunting!

Translated by