MathGroup Archive 2008

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

Search the Archive

Re: SparseArray


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