Re: Set diagonal of square matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg116976] Re: Set diagonal of square matrix
- From: Ray Koopman <koopman at sfu.ca>
- Date: Sun, 6 Mar 2011 05:43:17 -0500 (EST)
- References: <ikt5e6$t68$1@smc.vnet.net>
On Mar 5, 3:05 am, Szabolcs <szhor... 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. ReplacePart[{{0,0,0}, {0,0,0}, {0,0,0}}, {i_,i_} :> {a,b,c}[[i]] ] {{a,0,0}, {0,b,0}, {0,0,c}}