Slow calculation of a determinant?



Hey yes! Setting ratmx:true does really speed things up - for matrix
inversion as for determinants. I wonder, following Adrej's remark, why it's
set to be false by default?

-Alasdair

On 11/6/05, Andrej Vodopivec  wrote:
>
> You are probably right. I just looked at the output of
>
> (%i1) matrix([a,b,c,d], [e,f,g,h], [i,j,k,l], [m,n,o,p]);
> (%o1) matrix([a,b,c,d],[e,f,g,h],[i,j,k,l],[m,n,o,p])
> (%i2) determinant(%);
> (%o2)
>
> a*(f*(k*p-l*o)-g*(j*p-l*n)+h*(j*o-k*n))-b*(e*(k*p-l*o)-g*(i*p-l*m)+h*(i*o=
-k*m))+c*(e*(j*p-l*n)-f*(i*p-l*m)+h*(i*n-j*m))-d*
> (e*(j*o-k*n)-f*(i*o-k*m)+g*(i*n-j*m))
>
> and assumed that determinant uses laplace expansion theorem. I didn't loo=
k
> at the source.
>
> Maybe ratmx should be set to true by default. It would have saved me some
> time...
>
> Andrej
>
>
> > 1. try newdet( ); it seems to be much faster, and, I thought
> > THAT was the program to use minor expansion. It took 6 seconds
> > on my computer.
> >
> > 2. The determinant() program is supposed to use gaussian elimination,
> and
> > in fact if you look at the source file mat.lisp you will see an
> > implementation
> > of fraction free Gaussian elimination, which appears to be
> > what Andrej re-implemented.
> >
> > 3. if you set ratmx:true, the time it takes on my machine
> > it takes 0.20 seconds.
> >
> > 4. if you leave ratmx:false, the time it takes is minutes. I have
> > no idea what algorithm it is using.
> >
> >
> >
> > Of course, if you specialize the algorithm
> > to numbers, especially floats, it may be much faster.
> >
> > RJF
> >
> > Andrej Vodopivec wrote:
> >
> >> Maxima uses minor expansion to calculate determinants. This is the bes=
t
> >> algorithm for calculating (small) symbolic determinants. But this
> >> algorithm is not the best choice for large matrices with integer
> >> entries.
> >> I use this code for larger matrices:
> >>
> >> http://wxmaxima.sourceforge.net/files/idet.lisp
> >>
> >> HTH,
> >> Andrej
> >>
> >>
> >>
> >>>I'm just experimenting with Maxima, and comparing it to two systems I
> >>>already have: MuPAD and Scilab. Just for fun, I decided to get each
> >>> system
> >>>to evaluate the determinant of a 16x16 matrix with entries randomly
> >>> chosen
> >>>from the integers 0..9. I timed each one:
> >>>
> >>>MuPAD:
> >>>
> >>>
> >>>>>m:=matrix(16,16,(i,j)->random() mod 10)
> >>>>>time(linalg::det(m))
> >>>
> >>>95
> >>>
> >>>(Output is in milliseconds).
> >>>
> >>>Scilab:
> >>>
> >>>-->m=floor(rand(16,16)*10)
> >>>-->tic,det(m),toc
> >>>ans
> >>>6.137E+13
> >>>ans
> >>>0.04
> >>>
> >>>(Output in seconds.)
> >>>
> >>>Maxima:
> >>>
> >>>(%i1) showtime:true;
> >>>(%i2) f[i,j]:=random(10)$
> >>>(%i3) m:genmatrix(f,16,16);
> >>>(%i4) determinant(m);
> >>>Evaluation took 817.71 seconds (866.82 elapsed) using 94.295 MB.
> >>>(%o4) 470231216693085
> >>>
> >>>That's nearly 14 minutes! What's going on here? Surely such a
> >>>straightforward calculation as this should be nearly instantaneous? An=
d
> >>>look
> >>>at the memory usage!
> >>>
> >>>-Alasdair
> >>>
> >>
> >>
> >> _______________________________________________
> >> Maxima mailing list
> >> Maxima@math.utexas.edu
> >> http://www.math.utexas.edu/mailman/listinfo/maxima
> >
> > _______________________________________________
> > Maxima mailing list
> > Maxima@math.utexas.edu
> > http://www.math.utexas.edu/mailman/listinfo/maxima
> >
>
>
> --
> Andrej Vodopivec http://www.fmf.uni-lj.si/~vodopivec
> Department of Mathematics, IMFM
> Jadranska 19, 1000 Ljubljana
> Slovenia
>