Re: matrices & polynomials in mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg27270] Re: matrices & polynomials in mathematica
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Sun, 18 Feb 2001 02:52:07 -0500 (EST)
• References: <96iqj6\$d90@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"news.tue.nl" <student at tue.nl> wrote in message
news:96iqj6\$d90 at smc.vnet.net...
> 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.
>
>
>
>

```

• Prev by Date: Re: Problem: a matrix and a box...
• Next by Date: Re: Problem: a matrix and a box...
• Previous by thread: Re: matrices & polynomials in mathematica
• Next by thread: Limit[ Sign[],x->Infinity ]