how to calculate modulus in matlab ?

조회 수: 10 (최근 30일)
ahmed
ahmed 2013년 5월 15일
편집: James Tursa 2023년 5월 31일
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.

채택된 답변

James Tursa
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:

추가 답변 (3개)

Roger Stafford
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.

Walter Roberson
Walter Roberson 2013년 5월 15일
  댓글 수: 1
Roger Stafford
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
ahmed 2013년 5월 17일
Thanks for your help any way , but even the powermod function or any of the above functions in url links can calculate the correct answer which is 3 .
trying:
powermod( (4^15) * (21^13) , 1 , 47 ) gives 21 but the correct ans using windows calculator is 3 and it is equivelant to the answer in my cryptography study book .
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 5월 17일
편집: James Tursa 2023년 5월 31일
mod(powermod(4, 15, 47) * powermod(21, 13, 47), 47)
ans = 3

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by