I want to realize a function R
with parameters a, b, w
which creates an M × M
Givens rotation (sometimes called Jacobi rotation) matrix; i.e., a matrix R
of size M × M
equal to the identity matrix except for the entries in position
(a, a)
, (a, b)
, (b, a)
and (b, b)
which are substituted with the entries of the matrix
{{Sin[w], Cos[w]}, {Cos[w], -Sin[w]}}
The solution I found is
R[a_, b_, w_] := Table[
If[(m == a && n == a),
Sin[w],
If[(m== a && n == b),
Cos[w],
If[(m == b && n == a),
Cos[w],
If[(m == b && n == b),
-Sin[w],
If[m == n, 1, 0]
]
]
]
], {m, 1, M}, {n, 1, M}]
but I wonder if there is a simpler/more efficient/elegant way to define the function.
{{Sin[w], Cos[w]}, {Cos[w], -Sin[w]}}
is not a rotation matrix, since its determinant is not1
. $\endgroup$