Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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$.

share|improve this question
up vote 5 down vote accepted

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


enter image description here

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

share|improve this answer
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. – Eden Harder Dec 15 '13 at 2:35
e*q suffices, because QRDecomposition[eq = e*q][[2]] == QRDecomposition[q.eq][[2]]. – Ray Koopman Dec 15 '13 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}]. – Ray Koopman Dec 15 '13 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 (:=). – ybeltukov Dec 15 '13 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 *) – Ray Koopman Dec 16 '13 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};
 (* Start with diagonal matrix and rotate the entire thing *)
 m = RotationMatrix[{{0, 0, 1}, unitSphere[θ, ϕ]}].DiagonalMatrix[λ];
 {u, w, v} = SingularValueDecomposition[m];

   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}]


share|improve this answer
Thanks! I also want to reduce the variables. – Eden Harder Dec 15 '13 at 3:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.