MathGroup Archive 2011

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

Search the Archive

check if a square matrix is diagonal

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115286] check if a square matrix is diagonal
  • From: benyaya <xiaochu at gmail.com>
  • Date: Thu, 6 Jan 2011 02:06:17 -0500 (EST)

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: Augmenting Mathematica documentation - a serious proposal
  • Next by Date: Re: Solving 2nd order PDE into Mathematica
  • Previous by thread: Re: Augmenting Mathematica documentation - a serious proposal
  • Next by thread: Re: check if a square matrix is diagonal