
interesting case where CAS computation makes a large numerical difference
Posted:
Jun 7, 2012 8:09 PM


Interesting article on Cleve's corner today:
http://blogs.mathworks.com/cleve/
On floating points issue and his analysis why it happened.
But wanted to show here that doing the same thing using a CAS removed the problem (as would be expected, nothing surprising, since using pure integers). Ofcourse one can argue about speed and performance in real large numerical problems and all of this.
But I just thought some here might like to see it.
It is finding the Determinant of 2 by 2 matrix of integers. The correct answer is 1.
I tried the example shown on some software I have, here is the result. I run in on matlab 2112a,matlab 2112a/symbolic,octave, Mathematica,Maple:
 matlab 2112a  EDU>> X = [ 63245986, 102334155 102334155, 165580141];
EDU>> det(X)
1.5249
 matlab 2112a/Symbolic  EDU>> syms X EDU>> X=sym([ 63245986, 102334155;102334155, 165580141]) [ 63245986, 102334155] [ 102334155, 165580141] EDU>> det(X) 1  GNU Octave, version 3.2.4 on Linux  octave:3> X X = 63245986 102334155 102334155 165580141
octave:4> det(X) ans = 0.99950
 Mathematica 8.04 Clear["Global`*"]; a=63245986; b=102334155; c=102334155;d=165580141; mat={{a,b},{ c,d}}; Det[mat]
Out[25]= 1
Maple 14
with(LinearAlgebra): M:=Matrix([[63245986,102334155],[102334155,165580141]]); [ 63245986 102334155] M := [ ] [102334155 165580141]
Determinant(M); 1 
But before we go celebrate, justed wanted to point that even the CAS programs do not generate 1 when the numbers are made to be floating points. Interesting also to see now the results:
 Mathematica 8.04 Clear["Global`*"]; a=63245986.;b=102334155.;c=102334155.;d=165580141.; mat={{a,b},{c,d}}; Det[mat]
Out[22]= 1.5249
Maple 14
> with(LinearAlgebra): > M:=Matrix([[63245986.0,102334155.0],[102334155.0,165580141.0]]); [ 8 9] [0.632459860 10 0.1023341550 10 ] M := [ ] [ 9 9] [0.1023341550 10 0.1655801410 10 ]
> Determinant(M); 0.

Mathematica result now agrees with Matlab's. I am not sure why Maple gives zero. May be I need to use an option somewhere for the Matrix construtor. Not a Maple expert.
I guess it is true then that God made the integers and the rest is the work of man :)
Nasser

