Solving polynomial with matrix coefficients

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.

You might consider using the function MatrixFunction.

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…

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.

Sure. Attached.

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.

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?

“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}} *)

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?

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}} *)

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.

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}} *)

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