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.
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
Poly = (1 + x)^3 + 2;
clist = CoefficientList[Poly, x];
MatPoly = (MatrixPower[x, #] & /@ (Range[Length[clist]] -1)).clist
Erich
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...