# What's the best way to generate all the upper triangular matrix whose singular values are given?

For example, given $\lambda_1 = 1, \lambda_2 = 2, \lambda_3 = 3$, what's the best way to generate all the upper triangular matrix ($3\times 3$) whose singular values are $\lambda_i$?

Note:Given a matrix $A$, if the eigenvalues of $A^HA$ are $\lambda_i \geq 0$, then $\sqrt{\lambda_i}$ are the singular values of $A$. $A^H$ is the conjugate transpose of $A$. Generally, If $B = U A V$ where $U,V$ are all unitary matrix, then $B$ have the same singular values of $A$.

One can proof that QRDecomposition[m][[2]] returns the upper triangular matrix with the same singular values

e = {1, 2, 3};
n = Length[e];

q := Orthogonalize[RandomReal[NormalDistribution[], {n, n}] +
I RandomReal[NormalDistribution[], {n, n}]];

r = QRDecomposition[q.DiagonalMatrix[e].q][[2]];

SingularValueDecomposition[r][[2]] // Diagonal
(* {3., 2., 1.} *)

MatrixForm@Chop[r]


Here q is the generator of the random unitary matrix (note the := sign).

• Thanks! Generally, If $B = U A V$ where $U,V$ are all unitary matrix, then $B$ have the same singular values of $A$. But here only consider the case q.DiagonalMatrix[e].q. Dec 15, 2013 at 2:35
• e*q suffices, because QRDecomposition[eq = e*q][[2]] == QRDecomposition[q.eq][[2]]. Dec 15, 2013 at 8:42
• My earlier comment was made too hastily, before actually checking. The two versions of r are not necessarily equal, because r is determined only to within a multiplier of ±1 for each row. The test is And @@ MapThread[#1 == #2 || #1 == -#2 &, {r1, r2}]. Dec 15, 2013 at 10:43
• @EdenHarder I think that q.DiagonalMatrix[e].q is the general case. It is equivalent to $UAV$ with the diagonal matrix $A$. Each q is different because I use the delayed set (:=). Dec 15, 2013 at 13:17
• The QR decompositions of $AV$ and $UAV$ give equivalent $R$ matrices, so $U$ is not necessary. n = Length[e = {1, 2, 3}]; q := Orthogonalize[RandomReal[NormalDistribution[], {n, n}] + I*RandomReal[NormalDistribution[], {n, n}]]; r1 = Last@QRDecomposition[eq = e*q]; r2 = Last@QRDecomposition[q.eq]; And @@ MapThread[#1 == #2 || #1 == -#2 &, {r1, r2}] (* True *) Dec 16, 2013 at 0:56

Not a full answer but perhaps something you can work from. Thinking of a matrix as the action it does on the unit sphere $\{Ax ,\|x\| == 1\}$ which is an ellipsoid centered at 0, as it is the image of a linear transformation. The singular values represent the length of the semiaxes, the only freedom that remains is picking the orthonormal basis representing the direction of the semiaxes. Whatever is picked it should be possible to upper triangularize.

unitSphere[θ_, ϕ_] := {Cos[θ] Sin[ϕ], Sin[θ] Sin[ϕ], Cos[ϕ]};
λ = {1, 2, 3};
Manipulate[
m = RotationMatrix[{{0, 0, 1}, unitSphere[θ, ϕ]}].DiagonalMatrix[λ];
{u, w, v} = SingularValueDecomposition[m];

Show[
ParametricPlot3D[
m.unitSphere[a, b], {a, 0, 2 Pi}, {b, 0, Pi}, PlotStyle -> Opacity[0.3], Mesh -> None],
Graphics3D[{Arrow[{{0, 0, 0}, #}] & /@ Transpose[u.w]}],
PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}},
PlotLabel -> Diagonal[w]
],
{θ, 0, 2 Pi}, {ϕ, 0, Pi}]


• Thanks! I also want to reduce the variables. Dec 15, 2013 at 3:22