3

I want a function to take a polynomial from a list, plug a certain matrix *T* into that polynomial, and return the answer as another matrix. My program uses the *applyPoly* function suggested by a user in response to:

Here is my code:

```
applyPoly[poly_, var_, A_?MatrixQ] :=
With[{c = CoefficientList[poly, var]},
c.MapIndexed[MatrixPower[A, #2[[1]] - 1] &, c]]
Compute[a_, b_, c_] := (
p[x_] := x^4 - c*x^3 - b*x^2 - a*x;
T := {{0, 0, 0, 0}, {1, 0, 0, a}, {0, 1, 0, b}, {0, 0, 1, c}};
L := FactorList[p[x]]; s = Length[L]; R = {};
Do[R = Append[R, Simplify[p[x]/L[[i + 1, 1]]]], {i, s - 1}];
u = Length[R];
Do[r[x_] := R[[i]]; Print[applyPoly[r[x], x, T]], {i, u}])
Compute[1,2,3]
```

In Mathematica 8, this returns the correct matrix output:

```
{{-1,0,0,0},{-2,0,0,0},{-3,0,0,0},{1,0,0,0}}
{{0,0,0,0},{1,0,0,1},{0,1,0,2},{0,0,1,3}}
```

But in Mathematica 9, I get an error:

Dot::rect: Nonrectangular tensor encountered. >>

{-1,-2,-3,1}.{MatrixPower[{{0,0,0,0}, {1,0,0,1},{0,1,0,2},{0,0,1,3}},0],{{0,0,0,0}, {1,0,0,1},{0,1,0,2},{0,0,1,3}}, {{0,0,0,0}, {0,0,1,3},{1,0,2,7}, {0,1,3,11}}, {{0,0,0,0}, {0,1,3,11}, {0,2,7,25}, {1,3,11,40}}}

Dot::rect: Nonrectangular tensor encountered. >>

{0,1}.{MatrixPower[{{0,0,0,0},{1,0,0,1},{0,1,0,2},{0,0,1,3}},0],{{0,0,0,0},{1,0,0,1},{0,1,0,2},{0,0,1,3}}}

I understand that 8 and 9 must handle matrix or list objects in different ways. What is the difference, and how can I alter my program so that it works in 9?

I think

`MatrixPower`

chokes on your matrix not being positive-definite... – sebhofer – 2013-07-19T13:12:20.720It's funny, because the documentation says that

`MatrixPower`

was last modified in version 6. – sebhofer – 2013-07-19T13:13:55.557In version 9, have you tried

`MatrixFunction`

? – b.gates.you.know.what – 2013-07-19T13:25:52.183@b.gatessucks I did try

`MatrixFunction`

but I seem to remember it had problems with using list entries. I'll get back to you later when I can look at those files. – nardol5 – 2013-07-19T14:52:57.850