how to calculate modulus in matlab ?
Mostra commenti meno recenti
Hi everyone,
the question seems simple as using mod works for small numbers not for large numbers.
i want to calculate mod( (4^15)*(21^13),47) the matlab ans= 21 but the correct ans = 3 using the windows calculator. is there any way in matlab to calculate such modulus ?
Thanks in advance.
Risposta accettata
Più risposte (3)
Roger Stafford
il 15 Mag 2013
0 voti
The number you describe is far too large for accurate numerical computation using only 'double' floating points numbers. However, the 'mod' function also works with symbolic numbers using the symbolic toolbox. You can compute with these to any accuracy you wish.
Walter Roberson
il 15 Mag 2013
mod(mod( (4^15), 47) * mod((21^13),47), 47)
See also
1 Commento
Roger Stafford
il 16 Mag 2013
The number 21^13 as computed with 'double' is too large to be computed exactly. Its least five bits must necessarily be rounded to zeros to fit within 53 bits and consequently it gives:
mod(21^13,47) = 2,
whereas the true modulo 47 value is:
mod(mod(21^7,47)*mod(21^6,47),47) = 7.
ahmed
il 17 Mag 2013
0 voti
1 Commento
Walter Roberson
il 17 Mag 2013
Modificato: James Tursa
il 31 Mag 2023
mod(powermod(4, 15, 47) * powermod(21, 13, 47), 47)
Categorie
Scopri di più su Number Theory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!