MathGroup Archive 2006

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

Search the Archive

Re: Define a matrix function with size as argument

On 11/15/06 at 6:45 AM, sgiannerini at (Simone Giannerini)

>I am quite new to Mathematica and I have the following problem I
>could not find track of both in the Forum and in the documentation.
>I need to define a matrix function with size of the matrix as an
>argument. The function produces a tridiagonal matrix:

>Q[w_] := MatrixForm[SparseArray[
>{i_, j_} /; Abs[i - j] <= 1 -> Which[i < j,
>a[i - 1]*(1 - (i - 1)/(2*w)), i > j,
>(a[-i + 2*w + 1]*(i - 1))/(2*w), i == j,
>(-(1 - (i - 1)/(2*w)))*a[i - 1] -
>(a[-i + 2*w + 1]*(i - 1))/(2*w) + 1],
>{2*w, 2*w}]]

>dum = Q[2]

>the problem is that dum is not recognized as a matrix so that
>operations like Inversion and the like do not work.

Don't use MatrixForm in the function Q[w_]. MatrixForm puts a 
wrapper around the array and is causing your problem. If you 
prefer (as I do) to see the array displayed in MatrixForm, the 
best way to achieve this is to set the default output to 
TraditionalForm and forget the existence of MatrixForm altogether.
To reply via email subtract one hundred and four

  • Prev by Date: RE:Need Help: Can not use Ticks under PolarPlot
  • Next by Date: Re: Mathematica 5.2 redraw errors with X and nvidia graphics card
  • Previous by thread: Define a matrix function with size as argument
  • Next by thread: Re: Define a matrix function with size as argument