Re: Define a matrix function with size as argument
- To: mathgroup at smc.vnet.net
- Subject: [mg71403] Re: Define a matrix function with size as argument
- From: "dimitris" <dimmechan at yahoo.com>
- Date: Thu, 16 Nov 2006 00:55:08 -0500 (EST)
- References: <ejf10f$4pt$1@smc.vnet.net>
Try
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}]
dum = Q[2]
SparseArray[<\[InvisibleSpace]10\[InvisibleSpace]>,{4,4}]
Here is dum
MatrixForm[dum]
Here is its inverse
Inverse[dum]
the transpose
Transpose[dum]
SparseArray[<\[InvisibleSpace]10\[InvisibleSpace]>,{4,4}]
MatrixForm[%]
and so on...
Regards
Dimitris
Simone Giannerini wrote:
> 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
> ______________________________________________________