Is there a way to solve wrong results when using (mod) operation?

1 回表示 (過去 30 日間)
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014 年 4 月 20 日
Hi all,
I am working with many (mod) operations to create my own functions in matlab. However, I face a problem of wrong results that are appears. For example,
***** Manuale calculations ***********
temp = (16667 * 16667 * 16667 ) = 4629907412963
temp = = 2533 * 4629907412963 = 11727555477035279
temp = temp % 25000
temp = 10279
***** Matlab calculations ***********
temp = (16667 * 16667 * 16667 )
temp = 2533 * 4.6299e+12
temp = 1.1728e+16
temp = mod (1.1728e+16 , 25000)
temp = 10280
******************************
As you can see, there are two different results even it is just one value! Also I have another
example with a huge difference between the two results.
Is there a convenient way to solve this issue?
Thanks in advance!
  9 件のコメント
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014 年 4 月 28 日
It works with the symbolic toolbox.
Thank you so much : )
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014 年 4 月 28 日
Both answers helps me
Thank you Geoff Hayes & Walter Roberson

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2014 年 4 月 20 日
You could work with int64 or uint64 datatype. That would postpone the problem.
To solve the problem (for most practical purposes) you would need to switch to a high precision arithmetic system, such as using the symbolic toolbox or using John D'Errico's File Exchange contribution "VPI"
  4 件のコメント
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014 年 4 月 28 日
It works with the symbolic toolbox.
Thanks for your comments and explanations : )
Thank you so much
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014 年 4 月 28 日
Both answers helps me
Thank you Geoff Hayes & Walter Roberson

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by