# Solving polynomial with matrix coefficients

**URL:** <https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159>\
**Category:** Questions\
**Tags:** mathematica, algebra\
**Created:** [November 29, 2014, 9:35pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159 "2014-11-29T21:35:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [November 29, 2014, 9:35pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/1 "2014-11-29T21:35:44Z")

</div>

I have a polynomial B in u that I want to solve, where u is an operator. It’s of degree three so there will be three operators that solve it, and I want the solutions given as matricies.

My current code is

```
L[u_] = Array[L, {3, 3}] + {{u, 0, 0}, {0, u, 0}, {0, 0, u}}

t[\[Epsilon]] = {{1, \[Epsilon]1, \[Epsilon]2}, {-\[Epsilon]1, 
   1, \[Epsilon]3}, {-\[Epsilon]2, -\[Epsilon]3, 1}}

T[u_] = L[u].t[\[Epsilon]]

The polynomial for B is

B = T[u][[2, 3]] (T[u][[1, 2]] T[u - I][[2, 3]] - 
     T[u][[1, 3]] T[u - I][[2, 2]]) - 
  T[u][[1, 3]] (T[u][[1, 3]] T[u - I][[2, 1]] - 
     T[u][[1, 1]] T[u - I][[2, 3]])

The L[i, j] are also matricies given by

L[1, 1] = I/3 {{2, 0, 0}, {0, -1, 0}, {0, 0, -1}}
L[2, 2] = I/3 {{-1, 0, 0}, {0, 2, 0}, {0, 0, -1}}
L[3, 3] = I/3 {{-1, 0, 0}, {0, -1, 0}, {0, 0, 2}}
L[1, 2] = I {{0, 0, 0}, {1, 0, 0}, {0, 0, 0}}
L[1, 3] = I {{0, 0, 0}, {0, 0, 0}, {1, 0, 0}}
L[2, 1] = I {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}}
L[2, 3] = I {{0, 0, 0}, {0, 0, 0}, {0, 1, 0}}
L[3, 1] = I {{0, 0, 1}, {0, 0, 0}, {0, 0, 0}}
L[3, 2] = I {{0, 0, 0}, {0, 0, 1}, {0, 0, 0}}

```

I tried don’t know how to tell it that u is a 3x3 matrix and how to find that matrix. Up until now I was writing u= x {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}} and B resulted in me having a 3x3 matrix with a polynomial of degree 3 on each element of the diagonal which isn’t what I want.

Any help appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![antononcube](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/antononcube/32/7348_2.png) [@antononcube](https://community.wolfram.com/u/antononcube)\
**Post date:** [November 29, 2014, 10:49pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/2 "2014-11-29T22:49:33Z")

</div>

You might consider using the function `MatrixFunction`.

---

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [November 30, 2014, 1:00am UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/3 "2014-11-30T01:00:55Z")

</div>

I’ve tried using it, I put

m = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

and set f[u\_] = MatrixFunction[B[#] &, u] (note I fixed the definition of B in the first post and wrote in as B[u\_]

and then used the usual solve function for f[u]=m, and got some crazy answer it took about two minutes to compute.

Earlier up I did write u as u = Array[x, {3, 3}], so I’m not sure if that’s causing issues or not…

---

<div class="post-metadata">

**Author:** ![antononcube](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/antononcube/32/7348_2.png) [@antononcube](https://community.wolfram.com/u/antononcube)\
**Post date:** [November 30, 2014, 1:09am UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/4 "2014-11-30T01:09:47Z")

</div>

Can you attach a notebook with your code to the discussion?

It seems that your matrix equation can be unfolded into a set of equations using `Thread` and giving the equations and the corresponding variables to `Reduce`.

---

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [November 30, 2014, 1:15am UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/5 "2014-11-30T01:15:48Z")

</div>

Sure. Attached.

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [December 2, 2014, 2:34pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/6 "2014-12-02T14:34:19Z")

</div>

This is not very clear to me. Are you trying to do this?

```
sol = u /. Solve[Flatten[B[u]] == Flatten[m], Flatten[u]];

```

That gives many solution matrices expressed in terms of the epsilons.

---

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [December 2, 2014, 2:54pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/7 "2014-12-02T14:54:46Z")

</div>

It might be what I’m trying to do… I want to get matricies u that solve B[u]=0. I put your code into mine but it didn’t work - may I see your code please?

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [December 2, 2014, 3:42pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/8 "2014-12-02T15:42:46Z")

</div>

“My” code is just your code. I didn’t change anything that I recall.

```
L[u_] = Array[L, {3, 3}] + {{u, 0, 0}, {0, u, 0}, {0, 0, u}};
t[\[Epsilon]] = {{1, \[Epsilon]1, \[Epsilon]2}, {-\[Epsilon]1, 
    1, \[Epsilon]3}, {-\[Epsilon]2, -\[Epsilon]3, 1}};
T[u_] = L[u].t[\[Epsilon]];
B[u_] := T[u][[2, 3]] (T[u][[1, 2]] T[u - v][[2, 3]] - 
      T[u][[1, 3]] T[u - v][[2, 2]]) - 
   T[u][[1, 3]] (T[u][[1, 3]] T[u - v][[2, 1]] - 
      T[u][[1, 1]] T[u - v][[2, 3]]);
L[1, 1] = I/3 {{2, 0, 0}, {0, -1, 0}, {0, 0, -1}};
L[2, 2] = I/3 {{-1, 0, 0}, {0, 2, 0}, {0, 0, -1}};
L[3, 3] = I/3 {{-1, 0, 0}, {0, -1, 0}, {0, 0, 2}};
L[1, 2] = I {{0, 0, 0}, {1, 0, 0}, {0, 0, 0}};
L[1, 3] = I {{0, 0, 0}, {0, 0, 0}, {1, 0, 0}};
L[2, 1] = I {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}};
L[2, 3] = I {{0, 0, 0}, {0, 0, 0}, {0, 1, 0}};
L[3, 1] = I {{0, 0, 1}, {0, 0, 0}, {0, 0, 0}};
L[3, 2] = I {{0, 0, 0}, {0, 0, 1}, {0, 0, 0}};
u = Array[x, {3, 3}];
v = I {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};

sol = u /. Solve[Flatten[B[u]] == 0, Flatten[u]];
Length[sol]

(* Out[18]= 432 *)

```

Here is one of them.

```
sol[[1]]

(* Out[19]= {{-((2*I)/3), 0, 0}, {0, I/3, 0}, 
{-((I*(2*\[Epsilon]1*\[Epsilon]2 - \[Epsilon]2^2*\[Epsilon]3 - \[Epsilon]3^3 - 
         I*\[Epsilon]3*Sqrt[4*\[Epsilon]1^2 - \[Epsilon]2^4 - 
            2*\[Epsilon]2^2*\[Epsilon]3^2 - \[Epsilon]3^4]))/
          (2*(\[Epsilon]1*\[Epsilon]2^2 + \[Epsilon]1*\[Epsilon]3^2))), 0, I/3}} *)

```

---

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [December 3, 2014, 5:29pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/9 "2014-12-03T17:29:52Z")

</div>

When I change from

```
u=Array[x,{3,3}] 

```

to

```
u={{-((2*I)/3), 0, 0}, {0, I/3, 0}, 
{-((I*(2*\[Epsilon]1*\[Epsilon]2 - \[Epsilon]2^2*\[Epsilon]3 - \[Epsilon]3^3 - 
         I*\[Epsilon]3*Sqrt[4*\[Epsilon]1^2 - \[Epsilon]2^4 - 
            2*\[Epsilon]2^2*\[Epsilon]3^2 - \[Epsilon]3^4]))/
          (2*(\[Epsilon]1*\[Epsilon]2^2 + \[Epsilon]1*\[Epsilon]3^2))), 0, I/3}}

```

B[u] doesn’t equal zero though?

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [December 3, 2014, 7:02pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/10 "2014-12-03T19:02:38Z")

</div>

Properly substituted, you should get zero.

```
Together[B[u] /. Thread[Flatten[u] -> Flatten[sol[[1]]]]]

(* Out[20]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} *)

```

---

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [December 3, 2014, 7:28pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/11 "2014-12-03T19:28:41Z")

</div>

I see. Why is it not sufficient to just put it in normally? Sorry for not following - I’ve never seen the Flatten stuff before.

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [December 3, 2014, 7:32pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/12 "2014-12-03T19:32:07Z")

</div>

I guess I made it too complicated. You are correct that a direct substitution can be done. Here is what I should have shown:

```
B[sol[[1]]] // Together

(* Out[24]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} *)

```

---

<div class="post-metadata">

**Author:** ![ryanp16](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@ryanp16](https://community.wolfram.com/u/ryanp16)\
**Post date:** [December 3, 2014, 8:46pm UTC](https://community.wolfram.com/t/solving-polynomial-with-matrix-coefficients/4159/13 "2014-12-03T20:46:20Z")

</div>

Ah okay. Thank you very much! Why can’t the solution be substituted into B[u] normally though?
