how to calculate modulus in matlab ?
8 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
James Tursa
2013-5-17
See this newsgroup thread where Bruno Luong gives advice on how to do this calculation without using the symbolic toolbox:
0 个评论
更多回答(3 个)
Roger Stafford
2013-5-15
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.
0 个评论
Walter Roberson
2013-5-15
mod(mod( (4^15), 47) * mod((21^13),47), 47)
See also
1 个评论
Roger Stafford
2013-5-16
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
2013-5-17
1 个评论
Walter Roberson
2013-5-17
编辑:James Tursa
2023-5-31
mod(powermod(4, 15, 47) * powermod(21, 13, 47), 47)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!