Help with increased precision.

2 vues (au cours des 30 derniers jours)
alexander cooke
alexander cooke le 14 Juil 2020
Commenté : alexander cooke le 14 Juil 2020
I am trying to input a large number into a variable like so a=73167176531330624919225119674426574742355349194934.
However the problem is though that matlab doesn't store nunmbers with enough precision to hold the entire number in a single variable.
I've tried using vpa but that hans't help.
Can anyone give me a solution?

Réponse acceptée

John D'Errico
John D'Errico le 14 Juil 2020
Modifié(e) : John D'Errico le 14 Juil 2020
NO. You don't use vpa. No need to do that, and in fact, vpa would be the wrong tool to use anyway.
This works fine though.
a = sym('73167176531330624919225119674426574742355349194934')
a =
73167176531330624919225119674426574742355349194934
>> a + 2
ans =
73167176531330624919225119674426574742355349194936
You could also have used my VPI toolbox, but syms are faster than VPI. (That was not always the case as I recall, when I was first developing VPI.) And since you have the symbolic toobox anyway, just use it, properly, as I did there.
  1 commentaire
alexander cooke
alexander cooke le 14 Juil 2020
Works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by