Jump to content

Vector products: Difference between revisions

m
Line 1,228:
 
=={{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.) @ $~
ip=: +/ .* NB. inner product
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:
<lang j>cross=: [: > [: -&.>/ .(*&.>) (<"1=i.3) , ,:&:(<"0)</lang>
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.