4
$\begingroup$

I'm trying to write a function that takes in a skew symmetric matrix and returns the corresponding vector. When I write the following code, it works when I leave it as variables, but it does not work when I plug in numbers. Any help would be appreciated.

skewToq[{{0, -q3_, q2_}, {q3_, 0, -q1_}, {-q2_, q1_, 0}}] := {q1, q2, q3};
skewToq[{{0, -q3, q2}, {q3, 0, -q1}, {-q2, q1, 0}}]
{q1, q2, q3}

Now, when I plug in an actual skew-symmetric matrix, the function does not work...

skewToq[{{0, -3, 2}, {3, 0, -1}, {-2, 1, 0}}]
skewToq[{{0, -3, 2}, {3, 0, -1}, {-2, 1, 0}}]

Thanks!

$\endgroup$
0

4 Answers 4

8
$\begingroup$

There is a built-in function HodgeDual

Normal@HodgeDual[{{0, -3, 2}, {3, 0, -1}, {-2, 1, 0}}]
(* {-1, -2, -3} *)

Normal@HodgeDual[{-1, -2, -3}]
(* {{0, -3, 2}, {3, 0, -1}, {-2, 1, 0}} *)
$\endgroup$
2
  • 1
    $\begingroup$ ... of course there's a built-in. Should have known. $\endgroup$
    – evanb
    Commented Oct 23, 2014 at 23:44
  • $\begingroup$ If we define W as the skew-symmetric tensor and w as the axial vector, such that for a vector v, the relationship W v = w × v holds, the correct answers to get the axial vector of the skew-symmetric matrix are: w = Normal@HodgeDual[Transpose[W]] and w= Normal@HodgeDual[-W]. A negative sign is missing in the above answer, if you are seeking w based on W v = w × v. $\endgroup$
    – akr
    Commented Sep 15 at 10:58
3
$\begingroup$

As belisarius implies, Mathematica's pattern matcher matches literal expressions and not mathematical equalities.

Here's another implementation:

skewToq[M_] :=  If[
    And[Dimensions[M] == {3, 3}, M == -Transpose[M]], 
    {M[[3, 2]], M[[1, 3]], M[[2, 1]]}
    ]
skewToq[{{0, -q3, q2}, {q3, 0, -q1}, {-q2, q1, 0}}]
(* {q1, q2, q3} *)
skewToq[{{0, -3, 2}, {3, 0, -1}, {-2, 1, 0}}]
(* {1, 2, 3} *)
$\endgroup$
1
  • $\begingroup$ Thanks, this returns the correct answer. The Normal@HodgeDual function is not giving me the correct vector representation $\endgroup$
    – Imakang21
    Commented Oct 24, 2014 at 1:49
1
$\begingroup$

Skewfunction[{q1_,q2_,q3_}]:=MatrixForm[{{0,-q3,q2},{q3,0,-q1},{-q2,q1,0}}];

Skewfunction[{a,b,c}]

(0 -c b c 0 -a -b a 0)

$\endgroup$
0
$\begingroup$
ClearAll[sToq]

sToq[M_] /; AntisymmetricMatrixQ[M] := {M[[3, 2]], M[[1, 3]], M[[2, 1]]}

sToq[{{0, -q3, q2}, {q3, 0, -q1}, {-q2, q1, 0}}]
 {q1, q2, q3}
sToq[{{0, -3, 2}, {3, 0, -1}, {-2, 1, 0}}]
 {1, 2, 3}
sToq[{{0, 3, 2}, {3, 0, -1}, {-2, 1, 0}}]
 sToq[{{0, 3, 2}, {3, 0, -1}, {-2, 1, 0}}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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