Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

matrices & polynomials in mathematica

41 views
Skip to first unread message

news.tue.nl

unread,
Feb 16, 2001, 4:06:46 AM2/16/01
to
Hi,

I have the following problem.
I have written a mathematica-module that automatically produces a certain
polynomial as a result. But I want another module to use this first module
and fill in a matrix in this polynomial.
for example: f[x]=1+x+x^2
But when I compute f[A] where A is a matrix, mathematica interprets 1 as a
matrix filled with ones in stead of the identity-matrix. And A^2 is
pointswise multiplication in stead of matrix-multiplication.
Is there an option to let Mathematica know that the polynomial works on
matrices?

Chris

PS. I am aware of the possibility to multiply matrices using . (dot) but the
problem is that the polynomial is the result of some computations and I need
to have mathematica interpret this polynomial on matrices automatically.


Jens-Peer Kuska

unread,
Feb 17, 2001, 3:35:01 AM2/17/01
to
Hi,

two rules ???

f[x_?NumericQ] := 1 + x + x^2
f[x_?MatrixQ] /; Equal @@ Dimensions[x] :=
Module[{n = First[Union[Dimensions[x]]]},
IdentityMatrix[n] + x + Dot[x, x]
]

scan the coefficients of the polynomial for numbers and replace
the numbers by c_?NumericQ :> c*IndentityMatrix[c] and replacing times
by Dot[] may help. But essential the extension of of polynomial to
a matrix is very different from a scalar polynomial.

Regards
Jens

Erich Mueller

unread,
Feb 18, 2001, 12:13:13 AM2/18/01
to
You could try replacing Power with MatrixPower. Here is an example:

Poly = (1 + x)^3 + 2;
clist = CoefficientList[Poly, x];
MatPoly = (MatrixPower[x, #] & /@ (Range[Length[clist]] -1)).clist

Erich

Allan Hayes

unread,
Feb 18, 2001, 2:56:12 AM2/18/01
to
PolyMatrixReplace[poly_, var_, matr_] :=
With[{Id = IdentityMatrix[Length[matr]]},
Fold[#1.matr + #2 Id &, 0 matr, #] &[Reverse[CoefficientList[poly, var]]
]
]

Example:

poly= 3 +x +x^3;
mat = {{1,2},{2,5}};

PolyMatrixReplace[poly, x, mat]

{{33,72},{72,177}}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
h...@haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"news.tue.nl" <stu...@tue.nl> wrote in message
news:96iqj6$d...@smc.vnet.net...

0 new messages