Re: matrices & polynomials in mathematica

*To*: mathgroup at smc.vnet.net*Subject*: [mg27290] [mg27290] Re: [mg27273] matrices & polynomials in mathematica*From*: Tomas Garza <tgarza01 at prodigy.net.mx>*Date*: Sun, 18 Feb 2001 02:52:22 -0500 (EST)*References*: <200102160858.DAA13465@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

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 In[1]:= k = {c1, c2, c3, c4}; is the list of coefficients thus obtained (i.e., your polynomial is of degree 3). Take, for example, In[2]:= a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; and define, for an arbitrary matrix x, In[3]:= g[y_] := Dot[y, x] Then In[4]:= NestList[g, x, Length[k] - 2] Out[4]= {x, x.x, x.x.x} so that In[5]:= Rest[k].NestList[g, x, Length[k] - 2] Out[5]= 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: In[6]:= 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]) Example: In[7]:= polToMat[{{1, 2}, {3, 4}}, CoefficientList[1 + x + x^2, x]] Out[7]= {{9, 12}, {18, 27}} Tomas Garza Mexico City ----- Original Message ----- From: "news.tue.nl" <student at tue.nl> To: mathgroup at smc.vnet.net 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 the > problem is that the polynomial is the result of some computations and I need > to have mathematica interpret this polynomial on matrices automatically. > > > > >

**References**:**matrices & polynomials in mathematica***From:*"news.tue.nl" <student@tue.nl>