Vector products: Difference between revisions

Content added Content deleted
Line 1,228: Line 1,228:


=={{header|J}}==
=={{header|J}}==
Perhaps the most straightforward definition for cross product in J uses rotate multiple and subtract:
Based on [[j:Essays/Complete Tensor]]:

<lang j>cross=: (1&|.@[ * 2&|.@]) - 2&|.@[ * 1&|.@]</lang>

However, there are other valid approaches. For example, a "generalized approach" based on [[j:Essays/Complete Tensor]]:
<lang j>CT=: C.!.2 @ (#:i.) @ $~
<lang j>CT=: C.!.2 @ (#:i.) @ $~
ip=: +/ .* NB. inner product
ip=: +/ .* NB. inner product
cross=: ] ip CT@#@[ ip [</lang>
cross=: ] ip CT@#@[ ip [</lang>

Note that there are a variety of other generalizations have cross products as a part of what they do.

An alternative definition for cross (based on finding the determinant of a 3 by 3 matrix where one row is unit vectors) could be:
An alternative definition for cross (based on finding the determinant of a 3 by 3 matrix where one row is unit vectors) could be:
<lang j>cross=: [: > [: -&.>/ .(*&.>) (<"1=i.3) , ,:&:(<"0)</lang>
<lang j>cross=: [: > [: -&.>/ .(*&.>) (<"1=i.3) , ,:&:(<"0)</lang>