Re: RealDigits

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1808] Re: [mg1741] RealDigits
• From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
• Date: Mon, 31 Jul 1995 23:08:46 -0400
• Organization: University of Colorado, Boulder

```In article <DCBwLx.4GM at wri.com>,
Richard Mercer  <richard at seuss.math.wright.edu> wrote:
>(3) It uses the MapIndexed command, which I don't think I've ever used before.
>    Everybody should use this command at least once in their lifetime,
>    but probably not more than twice.

Now, now, don't disparage poor old MapIndexed.  It turns out to be
the perfect function for checking a matrix to see if it satisfies a
certain form.  For example, the following function checks a matrix
to see if it is diagonal:

DiagonalQ[m_] :=
And @@ Flatten[ MapIndexed[ #1==0 || Equal @@ #2 &, m, {2} ]]

Here's another one that checks for upper-triangularity:

UpperTriangularQ[m_] :=
And @@ Flatten[ MapIndexed[ #1==0 || LessEqual @@ #2 &, m, {2} ]]

It's similarly easy to write predicates for lower triangular, tridiagonal,
Toeplitz, etc, etc.  Note also that the DiagonalQ predicate works on
tensors of any rank simply by changing the level specification to {-1}.

If anybody has a better way to do this sort of thing, I'd love to see it.
To do it procedurally would require a nested loop.

Dave Wagner
Principia Consulting
(303) 786-8371
dbwagner at princon.com
http://www.princon.com/princon

```

• Prev by Date: Replacing terms and expanding one at a time
• Next by Date: Fit[] problem
• Previous by thread: Re: Replacing terms and expanding one at a time
• Next by thread: Re: RealDigits