Re: Linear algebra with generic dimensions
- To: mathgroup at smc.vnet.net
- Subject: [mg93691] Re: Linear algebra with generic dimensions
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sat, 22 Nov 2008 06:11:00 -0500 (EST)
- References: <gfubsq$eei$1@smc.vnet.net>
dudesinmexico wrote:
> I am looking for a way to do linear algebra computations where the
> dimensions of matrices and vectors are
> symbolic. Let me give an example to make this more clear. Say that you
> have a matrix whose
> generic element is defined as T_ij=rho^(j-i). If I want the square of
> the Frobenius norm of T, I can write
>
> Sum[Rho^(2 (j - i)), {i, 0, N - 1}, {j, 0, N - 1}], Element[{i, j},
> Integers]
>
> and Mathematica gives as an answer a function of N and Rho:
>
> (Rho^(2 - 2 N) (-1 + Rho^(2 N))^2)/(-1 + Rho^2)^2
>
> and this is what I want, a function of matrix size N and, in this
> case, a matrix parameter.
>
> However, If I use the built-in Norm[,"Frobenius"], I cannot specify an
> array with a generic dimension,
> and this is true of all the linear algebra functions. I think that
> what I need is a new "matrix type" holding the
> expression for a generic matrix element as a function of its indices
> and the names of the variables
> holding the dimensions. Then I could overload built-in functions like
> Dot[], Norm[], Tranpose[], etc..
> with new functions.
>
> Has this ever been done before? Is there any package or example
> showing how do implement these ideas?
>
> Thanks
> -Arrigo
>
Nobody else has responded to this with something more specific, so I
would like to comment that once you move away from explicit matrices and
vectors to more general symbolic representations, there are just so many
special cases. It is probably unreasonable to expect Mathematica to
supply this functionality directly.
You have raised the case where the matrix is of unknown size N, but
where a single formula can be used to represent all the elements.
Obviously there are many other special cases - such as the one where the
matrices are purely symbolic.
I think you have almost answered your own question. You need to create
objects such as
myMatrix[f[#1,#2]&,N]
and provide functions to operate on them:
myTranspose[myMatrix[fa_,nA_]]:= myMatrix[fa[#2,#1]&,nA]
etc.
In general, I would not overload the existing functions, but write your
own with a related name. Overloading can look elegant, but in
complicated situations it is easy to make a mistake which results in the
non-overloaded function being called inadvertently. The resulting error
messages can be challenging :)
David Bailey
http://www.dbaileyconsultancy.co.uk