Bill Allombert on Mon, 29 Oct 2012 14:07:43 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Matrix positive?


On Mon, Oct 29, 2012 at 11:37:54AM +0100, Karim Belabas wrote:
> * Dirk Laurie [2012-10-29 11:08]:
> > What's the quick way of testing whether every element
> > of a matrix is positive?
> 
> matrices. Currently, we have
> 
>   ? matid(2) > 0
>   ***   at top-level: matid(2)>0
>   ***                         ^--
>   *** _>_: forbidden comparison t_MAT (2x2) , t_INT.

It would be better to add a "and()" statement, like select()

and(f,M) = 
{ my (m,n); [m,n] = matsize(M);
  for(i=1,m, for(j=1,n, if (!f(M[i,j]), return(0))));
  return(1);
}

Cheers,
Bill.