Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

RE: Define a matrix function with size as argument

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71381] RE: [mg71358] Define a matrix function with size as argument
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 16 Nov 2006 00:53:20 -0500 (EST)

Simone,

I think your problem is using MatrixForm in the definition. MatrixForm is
not all that transparent as one might think or hope. Use MatrixForm in the
final output.

Q[w_] := 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}]

Then to define dum use parentheses to keep the definition independent of
MatrixForm.

(dum = Q[2]) // MatrixForm

That should work.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


From: Simone Giannerini [mailto:sgiannerini at gmail.com]


Dear all,

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.

Many thanks for your attention.

Kind regards,
______________________________________________________

Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126  Bologna,  ITALY
Tel: +39 051 2098262  Fax: +39 051 232153
______________________________________________________



  • Prev by Date: Re: Re: finding the (v,w) weighted degree of a polynomial
  • Next by Date: Re: Define a matrix function with size as argument
  • Previous by thread: Re: Define a matrix function with size as argument
  • Next by thread: Re: Define a matrix function with size as argument