Re: Set diagonal of square matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg117009] Re: Set diagonal of square matrix
- From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
- Date: Mon, 7 Mar 2011 05:49:23 -0500 (EST)
- References: <201103051104.GAA29846@smc.vnet.net>
On Sat, 5 Mar 2011, Szabolcs 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. > > here is one that works with SparseArray and Band mat + SparseArray[Band[{1, 1}] -> vec - Diagonal[mat], Dimensions[mat]] Oliver
- References:
- Set diagonal of square matrix
- From: Szabolcs <szhorvat@gmail.com>
- Set diagonal of square matrix