0
$\begingroup$

I am performing a finite-precision operation on a matrix A which I know precisely; call the result B. The operation is taking the square root by B = MatrixPower[A,1/2], but it's not quite relevant. The point is that the form of A is such that the output will contain a lot of entries equal to 0, simply because A has a lot of invariant subspaces spanned by the standard base vectors.

I would like to see resulting matrix is like: in the first approximation it interests me how many non-zero entries it has and where. The problem is, the entries of B which are supposed to be 0 come out as small reals of the type $1.234...\times 10^{-10}$. I've tried applying N to B with some modest requirement on precision, but this does not seem to help. Ideally, I would like to set all entries of B which are approximately 0 to precisely 0. Any help would be appreciated.

P.S. It just occurred to me that I can take a function f that maps small numbers to 0, and is identity otherwise, and apply it to B element-wise. But there should be a more elegant solution, it seems to me.

$\endgroup$
3
  • $\begingroup$ Take a look at Chop. $\endgroup$
    – Kuba
    Jun 23, 2013 at 13:26
  • $\begingroup$ @Kuba: Precisely what I needed! Thanks. $\endgroup$ Jun 23, 2013 at 13:28
  • $\begingroup$ This question has already been answered here. $\endgroup$
    – m_goldberg
    Jun 23, 2013 at 13:38

1 Answer 1

2
$\begingroup$

Perhaps you will find Chop useful.

$\endgroup$
1
  • $\begingroup$ Chop is just what I was looking for. Thank you! $\endgroup$ Jun 23, 2013 at 13:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.