# FindInstance of Matrix elements with dictionary

I'm a complete beginner at Mathematica, I'm trying to find a matrix A which when squared gives a specific solution. The elements of matrix A are k-th roots of unity (which I will specify), or if there is no solution, their absolute value should be 1.

Below is my attemp at the problem:

c = IdentityMatrix*10 - Reverse[IdentityMatrix*6];
A = Array[x, {10, 10}];
FindInstance[A^2 == c && Abs[x] == 1, x];


This does not work with the error indInstance::exvar: "The system contains a nonconstant expression x[1,1] independent of variables {x}. 1. How should I specify a dictionary, i.e. the k-th roots of unity? 2. How to fix the error?

• your c is just IdentityMatrix*16, so the answer is (IdentityMatrix*4) Dec 6, 2016 at 12:43
• It's actually in a X shape, non-zero elements on the diagonal and flipped diagonal. Sorry for the trouble, I've corrected the code Dec 6, 2016 at 14:57
• 1. Avoid capitalized variables, as these may conflict with builtins. 2. m^2 is elementwise square. m.m is matrix square. 3. If you use x[1,1] as a symbolic variable, you can't also use x. You probably wanted to specify Abs[...]==1 for each x[i,j] separately, and then again specify them separately in FindInstance. That's 100 symbolic variables. That's too many and you won't get a solution in a reasonable time. Dec 6, 2016 at 15:03
• But I don't know how to solve this problem. Dec 6, 2016 at 15:03

Set up, and define all variables used:

c = IdentityMatrix*10 - Reverse[IdentityMatrix*6];
A = Array[x, {10, 10}];
eqs = Thread[Map[Abs, vars = Variables[A]] == 1];


This works, as can be seen here:

s = FindInstance[A^2 == c, vars][];
Simplify[(A^2 /. s) == c]


True

However, with the additional stipulation that the absolute values of all elements are 1, no solution presents itself:

s = FindInstance[Join[{A^2 == c}, eqs], vars]


{}