Asked by ahmed
on 15 May 2013

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.

*No products are associated with this question.*

Answer by James Tursa
on 17 May 2013

Accepted answer

See this newsgroup thread where Bruno Luong gives advice on how to do this calculation without using the symbolic toolbox:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/329023

Answer by Roger Stafford
on 15 May 2013

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.

Answer by Walter Roberson
on 15 May 2013

mod(mod( (4^15), 47) * mod((21^13),47), 47)

See also

http://www.mathworks.com/matlabcentral/newsreader/view_thread/253630

http://www.mathworks.com/matlabcentral/fileexchange/7908-big-modulo-function

http://www.mathworks.com/help/symbolic/mupad_ref/powermod.html

http://www.mathworks.com/matlabcentral/fileexchange/39716-powermod

http://www.mathworks.com/matlabcentral/fileexchange/38516-powermod

Roger Stafford
on 16 May 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.

Answer by ahmed
on 17 May 2013

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 .

Opportunities for recent engineering grads.

## 0 Comments