MATLAB Answers

error in large integers

1 view (last 30 days)
Eigo Takkeda
Eigo Takkeda on 21 Mar 2012
I am currently working with fractions involving 10digit integers.
for example, typing 1168347147/863334886 into MATLAB produces the answer 4045/2989.
But I want to store the fractions exactly. How do I go about doing this?
Many thanks.

Answers (2)

Aldin
Aldin on 21 Mar 2012
Hi,
use vpa functon
for example:
vpa('4045/2989',100) ---> for hundred digits
  5 Comments
Aldin
Aldin on 22 Mar 2012
Do you know:
1168347147/863334886 = 4045/2989

Sign in to comment.


Walter Roberson
Walter Roberson on 22 Mar 2012
If you have the symbolic math toolbox, then
sym('1168347147/863334886')
Note that the result will be a symbolic number, not a double precision number.
  3 Comments
Aldin
Aldin on 22 Mar 2012
Hello sir Walter,
Can you please explain:
>> sym('1168347147/863334886')
ans =
1168347147/863334886
>> ans * 1,4
ans =
8178430029/4316674430
--------------------------
But if i check last result with 'vpa' function i got this:
>> vpa('863334886*1,4)
ans = 1208668840.4

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!