# How to quickly find a set of solutions that meet the requirements

Note: The following questions are from the 21th question of the 2010 Chinese Graduate Mathematical Entrance Examination (first set):

It is known that the canonical form of the quadratic form $$f\left(x_{1}, x_{2}, x_{3}\right)=x^{T} A x$$ under the orthogonal transformation $$x=Qy$$ is $$y_{1}^{2}+y_{2}^{2}$$, and the third column of Q is $$\left(\frac{\sqrt{2}}{2}, 0, \frac{\sqrt{2}}{2}\right)^{T}$$.Now I need to find the matrices A and Q.

I use the following code to calculate this problem, hoping to find a set of solutions that meet the requirements. But the following code runs all the time:

Q = {{x1, x2, Sqrt/2}, {x3, x4, 0}, {x5, x6, Sqrt/2}};
A = Array[x, {3, 3}];
FindInstance[
Thread[Transpose[Q] . A . Q == {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}}],
Join[{x1, x2, x3, x4, x5, x6}, Flatten[A]], Reals]


How can I improve this code to quickly find a set of solutions that meet the requirements?

The reference answer is $$Q=\left(\begin{array}{ccc} \frac{\sqrt{2}}{2} & 0 & \frac{\sqrt{2}}{2} \\ 0 & 1 & 0 \\ -\frac{\sqrt{2}}{2} & 0 & \frac{\sqrt{2}}{2} \end{array}\right)$$, $$A=Q\left(\begin{array}{lll} 1 & & \\ & 1 & \\ & & 0 \end{array}\right) Q^{T}=\frac{1}{2}\left(\begin{array}{ccc} 1 & 0 & -1 \\ 0 & 2 & 0 \\ -1 & 0 & 1 \end{array}\right)$$.

• Your reference answer doesn't satisfy Transpose[Q] . A . Q == {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}} ! Aug 12 '20 at 8:32
• @UlrichNeumann Note that the reference answer is $Q.A.Q^{T}$. if $Q=\left(\begin{array}{ccc} \frac{\sqrt{2}}{2} & 0 & \frac{\sqrt{2}}{2} \\ 0 & 1 & 0 \\ -\frac{\sqrt{2}}{2} & 0 & \frac{\sqrt{2}}{2} \end{array}\right)^{T}$, the answer is still correct Aug 12 '20 at 8:55
• I agree, my fault. But right Q as given in your question without transposition! Aug 12 '20 at 9:06

NMinimize evaluates quite fast:

mini = NMinimize[{#.# &[Flatten[Transpose[Q].A.Q - {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}} ]] + 10^10 #.# &[ Flatten[IdentityMatrix - Transpose[Q].Q]  ]},
Join[{x1, x2, x3, x4, x5, x6}, Flatten[A]], WorkingPrecision -> 15]

Transpose[Q].A.Q - {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}} /. mini[]
(*{{0.*10^-15, 0.*10^-15, 0.*10^-15}, {0.*10^-15, 0.*10^-15,0.*10^-15}, {0.*10^-16, 0.*10^-16, 0.*10^-15}}*)


The result for matrix A matches the reference answer

 A /. mini[] // Chop // Rationalize
(* {{1/2, 0, -(1/2)}, {0, 1, 0}, {-(1/2), 0, 1/2}} *)


but Q doesn't match the reference.

• Thank you very much. I hope to find a set of exact solutions rather than numerical solutions quickly. Aug 12 '20 at 7:43
• @Montevideo Ok you could try Minimize? Thereby you should add a constraint Q^T.Q==Identity Aug 12 '20 at 9:09
• After I added the constraint Q^T.Q==IdentityMatrix, it still runs without returning results. Aug 12 '20 at 9:52
• @Montevidoe I modified my answer. Minimize version doesn't evaluate... Aug 12 '20 at 10:14
• @Montevideo What a simple trick. Solve instead of FindInstance fgives 8 solutions quite fast. Aug 13 '20 at 7:21

I will leave the rigorous proof of the following to the interested reader:

v = {Sqrt[1/2], 0, Sqrt[1/2]};
qq = Transpose[Simplify[TrigExpand[Append[RotationMatrix[2 ArcTan[u]].
(Normalize /@ NullSpace[{#}]), #] &[v]]]]
{{(-1 + u^2)/(Sqrt (1 + u^2)), -((Sqrt u)/(1 + u^2)), 1/Sqrt},
{-((2 u)/(1 + u^2)), (1 - u^2)/(1 + u^2), 0},
{-((-1 + u^2)/(Sqrt (1 + u^2))), (Sqrt u)/(1 + u^2), 1/Sqrt}}

aa = FullSimplify[qq.{{1, 0, 0}, {0, 1, 0}, {0, 0, 0}}.Transpose[qq]]
{{1/2, 0, -1/2}, {0, 1, 0}, {-1/2, 0, 1/2}}

• This answer is great, but I don’t yet know its mathematical principles. Aug 15 '20 at 5:43