big numbers in matlab / sym math tool

I have a problem using very big numbers in matlab. For example, i want to calculate 26^29.
Without Sym Math Tool i get 1.081999577417210e+41, or with Sym Maths Tool 108199957741720993031339765987128356372480. If i try to find its value in modulus 35, i get mod(26^29,35)=20.
When i use wolframalpha, i get 108199957741720996894562347292921981566976, and the modulus value 31, which is correct!
In matlab, if i subtract the wolfram's correct value from 26^29, the result is 0!
I am doing this as a simulation of Euler's totient theorem, and i banged my head around it for a while until it became obvious that there is an error in matlab.
Is there any way to bypass this error, and what can be the source of it?

 Réponse acceptée

Sean de Wolski
Sean de Wolski le 14 Oct 2013
Modifié(e) : Sean de Wolski le 14 Oct 2013
x = sym('26^29');
mod(x,35)
ans =
31
I can only speculate how you were creating the sym before, but if you run:
sym(26^29)
It first evaluates
26^29
which is significantly larger than flintmax:
flintmax
ans =
9.0072e+15
So the rounding error of converting to double has already occurred.

1 commentaire

Milan
Milan le 14 Oct 2013
Thank you very much, Sean. I have made the exact mistake you mentioned by doing just sym(26^29).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Math dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by