Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: check if a square matrix is diagonal

  • To: mathgroup at
  • Subject: [mg115305] Re: check if a square matrix is diagonal
  • From: Thomas Dowling <thomasgdowling at>
  • Date: Fri, 7 Jan 2011 04:08:57 -0500 (EST)


Using your approach:

If[mtemp==Array[0 &,Dimensions[m]],Print["True"],Print["False"]]]

or maybe...

If[mtemp==Array[0 &,Dimensions[m]],Print["True"],Print["False"]]]

For example:




You may be interested in the following link to an old thread (I almost wrote

Tom Dowling

On Thu, Jan 6, 2011 at 7:06 AM, benyaya <xiaochu at> wrote:

> What I try to do is extract the diagonal, subtract if from the matrix,
> then compare the new matrix with 0.
> My code doesn't work out though, can anyone help? thanks a lot.
> checkIfDiagonalMatrix[m_] = Module[{d, mtemp},
>  d = Dimensions[m];
>  mtemp = DiagonalMatrix[Diagonal[m]] - m;
>  If[mtemp == Table[Table[0, {i, 1, d}], {i, 1, d}],
>   True,
>   False]
>  ]

  • Prev by Date: Extracting pixel values from an image under a polygon (region of interest)
  • Next by Date: Solving very large systems of ODEs with NDSolve
  • Previous by thread: Re: check if a square matrix is diagonal
  • Next by thread: Re: check if a square matrix is diagonal