MathGroup Archive 2011

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

Search the Archive

Re: Set diagonal of square matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116991] Re: Set diagonal of square matrix
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 6 Mar 2011 05:46:02 -0500 (EST)

n = 3;

mat = Array[m, {n, n}];

vec = Array[v, n];

mat + DiagonalMatrix[vec - Diagonal[mat]]

{{v[1], m[1, 2], m[1, 3]}, {m[2, 1], v[2], m[2, 3]}, {m[3, 1], 
  m[3, 2], v[3]}}


Bob Hanlon

---- Szabolcs <szhorvat at gmail.com> wrote: 

=============
Dear MathGroup members,

Is there any simple way to set the diagonal of a square matrix to a
vector (of appropriate length)?  Of course there are ways to do it,
but I was wondering if there was a simple, one-line way.




  • Prev by Date: Re: Plotting singularities
  • Next by Date: Re: Set diagonal of square matrix
  • Previous by thread: Re: Set diagonal of square matrix
  • Next by thread: Re: Set diagonal of square matrix