688^79 mod 3337 = 1570.
When I tried this at wolfram alpha I got:
but When I entered the same thing in Matlab, I get 364 as the answer. I got to be doing something wrong.
Any light on this will be appreciated.
688^79 mod 3337 = 1570.
When I tried this at wolfram alpha I got:
but When I entered the same thing in Matlab, I get 364 as the answer. I got to be doing something wrong.
Any light on this will be appreciated.
The reason is that Matlab uses double
floating-point arithmetic by default. A number as large as 688^79 can't be represented accurately as a double
. (The largest integer than can be accurately represented as a double
is of the order of 2^53).
To obtain the right result you can use symbolic variables, which ensures you don't lose accuracy:
>> x = sym('688^79');
>> y = sym('3337');
>> mod(x, y)
ans =
1570
vpa
means you have a finite, but adjustable, number of digits of precision. Maybe I don't understand what you're trying to say – you don't lose precision with respect to your specified value for digits
, but in manu cases you absolutely can lose precision relative to the true value using vpa
. –
Ravish 79^-1 mod 3220
(interpreted as PowerMod[79,-1,3220]
but will solve the standard remainder problem for 1/79 mod 3220
(interpreted as Mod[79^-1,3220]
). –
Trull vpa
, but the explanation was wrong. Thanks! I've corrected it –
Shunt My calculator is sending me the same answer than Wolfram, it also calculated the value for 688^79 so I would tend to believe Wolfram is right. You probably have overrun the capacities of Matlab with such a huge number and it is why it did not send the right answer.
© 2022 - 2024 — McMap. All rights reserved.
mod(double(688^79), 3337)
– Wampumpeagsym
and you will be able to calculate it correctly. – Wampumpeag