Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: matrices & polynomials in mathematica

  • To: mathgroup at
  • Subject: [mg27290] [mg27290] Re: [mg27273] matrices & polynomials in mathematica
  • From: Tomas Garza <tgarza01 at>
  • Date: Sun, 18 Feb 2001 02:52:22 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

Let your polynomial be f(v), and a the matrix you want to substitute into
the polynomial (I use a so as to avoid capital letters, which are bad form
in Mathematica). Obtain the coefficients of p using CoefficientList
 CoefficientList[poly, var] gives a list of coefficients of powers of var in
poly, starting with power 0). Suppose, for example, that

k = {c1, c2, c3, c4};

is the list of coefficients thus obtained (i.e., your polynomial is of
degree 3). Take, for example,

a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

and define, for an arbitrary matrix x,

g[y_] := Dot[y, x]


NestList[g, x, Length[k] - 2]
{x, x.x, x.x.x}

so that

Rest[k].NestList[g, x, Length[k] - 2]
c2 x + c3 x.x + c4 x.x.x

Then, in particular, for x = a all you have to do is add the first term:

First[k]*IdentityMatrix[Dimensions[x][[1]]] + Rest[k].NestList[g, x,
Length[k] - 2]

I suppose you could subsume all this into a function:

polToMat[a_?MatrixQ, k_List] := (g[y_] := Dot[y, a];
    First[k]*IdentityMatrix[Dimensions[a][[1]]] +
      Rest[k].NestList[g, a, Length[k] - 2])


polToMat[{{1, 2}, {3, 4}}, CoefficientList[1 + x + x^2, x]]
{{9, 12}, {18, 27}}

Tomas Garza
Mexico City

----- Original Message -----
From: "" <student at>
To: mathgroup at
Subject: [mg27290] [mg27290] [mg27273] matrices & polynomials in mathematica

> 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
> problem is that the polynomial is the result of some computations and I
> 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: Re: matrices & polynomials in mathematica