MathGroup Archive 2008

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

Search the Archive

Re: SparseArray

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92319] Re: SparseArray
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Sat, 27 Sep 2008 22:19:53 -0400 (EDT)
  • Organization: University of Bergen
  • References: <gbl365$m5v$1@smc.vnet.net>

Uli Wuerfel wrote:
> Hello,
> 
> I want to create a SparseArray with the elements being zero except for the diagonal elements and their direct neighbours. For those, I would like to assign them a value from another list, depending on the index i.
> 

 From your description it appears that you are trying to create a 
tridiagonal matrix.  Perhaps this syntax will be useful:

diagonal = Range[10]
lower = Range[10, 19]
upper = Range[20, 29]

mat = SparseArray[
   {Band[{1, 1}] -> diagonal,
    Band[{2, 1}] -> upper,
    Band[{1, 2}] -> lower}]

diagonal, upper, and lower are the lists containing the elements of the 
diagonals.


  • Prev by Date: Re: Manipulate / Space Phasor
  • Next by Date: convex optimization
  • Previous by thread: SparseArray
  • Next by thread: Re: SparseArray