There exists no solution. A product of rotation matrices is invertible, but the last 6 constraints introduce an entire row of zeros in U, making its rank of 5 or less, whence it must not be invertible.
Here, then, is optimal code: :-)
Solve[False, {}]
(0 seconds).
Well, maybe that wasn't so constructive. Let's see how we can find a product of rotation matrices in $n$ dimensions with specified components. This method minimizes the $L^2$ norm of the differences at the desired locations.
Begin by specifying the places and the values to attain at those places:
places = {{2, 4}, {1, 4}, {2, 5}, {1, 5}, {2, 6}, {1, 6},
{3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}};
targets = {.12, .11, .17, .11, .14, .11, 0, 0, 0, 0, 0, 0};
The objective function is the sum of squares of differences at those places:
objective[u_] := With[{x = u~Extract~places - targets}, x.x];
(This clear formulation is thanks to Mr.Wizard.)
Rotation matrices in higher dimensions, for rotations from one basis vector to another, look like the usual rotation matrices in two dimensions, with ones elsewhere on the diagonal:
rotationMatrix[t_, n_Integer, i_Integer, j_Integer] /; 1 <= i <= n && 1 <= j <= n && i != j :=
Module[{u = IdentityMatrix[n], s = Sin[t], c = Cos[t]},
u[[{i, j}, {i, j}]] = {{c, -s}, {s, c}}; u
]
The variables to parameterize a generic rotation correspond to these "basis vector" rotations, which when multiplied give an arbitrary rotation. The variables, vars, can be created at the same time the matrix product u is generated, cached via Sow, and collected via Reap:
With[{n = 6},
vars = Flatten[Last[Reap[
u = Dot @@ (Flatten[
Table[rotationMatrix[Sow[Unique["\[Theta]"]], n, i, j],
{i, 1, n - 1}, {j, i + 1, n}], 1])
]]]
];
Let's give it a whirl:
solution = NMinimize[objective[u], vars]
(0.69 seconds).
In this case, the best we can do is reduce the objective function to $1.$, not $0.$ (which would indicate a good solution). We might characterize what we have found as a least-squares fit to the targets. For the record, here it is:
Chop[u /. Last[solution]] // MatrixForm

U. – Leonid Shifrin Sep 28 '12 at 10:38Compileto help you here.Solveis not compilable and it very unlikely that you could write your own linear solver that does a better job thanSolve. If you have a 16x16 linear system and decimal approximations are sufficient, thenSolveshould be able to solve it nearly instantaneously. The information you have as written is really not quite sufficient to advise further, though. – Mark McClure Sep 28 '12 at 12:02