On 6/8/2012 2:47 PM, Axel Vogt wrote:
> On 08.06.2012 02:09, Nasser M. Abbasi wrote:
>>
>> Interesting article on Cleve's corner today:
>>
http://blogs.mathworks.com/cleve/
>>
>> On floating points issue and his analysis why it happened.
> ...
>> ---- matlab 2112a --------------
>> EDU>> X = [ 63245986, 102334155
>> 102334155, 165580141];
>>
>> EDU>> det(X)
>>
>> 1.5249
> ...
>
> The correct value in double precision round nearest
> would be 2.0, while in long double it would be 1.0,
> thus that is strange.
>
I do not know. Matlab uses double by default. I never
heared of long double in Matlab.
But I find this whole thing annoying sometimes
when one 'types' in integers into these packages but
because everything is done in floating point, (1 is 1.0 in
Matlab ofcourse) one ends up losing accuracy compared to
using CAS when 1 is really 1 and not 1.0
Here is a small example. Cross correlation between 2
sequences of integers:
---------- Mathematica ------------------
a={0,0,2,-1,3,7,1,2,-3,0,0};
b={0,0,1,-1,2,-2,4,1,-2,5,0,0};
c=Reverse[ListCorrelate[a,b,{-1,1},0]]
Out[31]= {0,
0,
0,
0,
10,
-9,
19,
36,
-14,
33,
0,
7,
13,
-18,
16,
-7,
5,
-3,
0,
0,
0,
0}
Matlab
-------------
A=[0,0,2,-1,3,7,1,2,-3,0,0];
B=[0,0,1,-1,2,-2,4,1,-2,5,0,0];
C=xcorr(A,B);
format long
C'
ans =
0.000000000000003
0.000000000000002
-0.000000000000002
0
9.999999999999998
-9.000000000000002
19.000000000000000
36.000000000000000
-14.000000000000000
33.000000000000000
-0.000000000000002
6.999999999999998
13.000000000000000
-18.000000000000000
16.000000000000004
-7.000000000000000
4.999999999999999
-2.999999999999998
-0.000000000000000
0.000000000000001
0.000000000000002
-0.000000000000004
0
These small difference can carry on to other computations ofcourse
causing more losses of accuracy.
May be one day, when computers become really fast and
has lots more memory, one can do things like computational
fluid dynamics and weather forecasting computation using nothing
but exact rational arithmetic. No more floating points!
May be in 100 years from now?
Or may be I am just dreaming here.
--Nasser