Oh-oh. I've screwed something up.
We can get correct results for arrays thus
  u cp"(1 1) v
which agrees with
  u cross"(1 1) v
but seems *not* to agree with my
  u cross v
I'll need to look into this! And into timings.

Sorry for the noise...
Patrick

On Sat, 8 Feb 2020, J. Patrick Harrington wrote:

The formula referenced there
 cp=:(1 _1 1 * 1 (-/ . *)\. ])@,.
compared to mine
 cross=: ((1: |.[)*(_1: |. ]))-((_1: |.[)*(1:|.]))
agree for single vectors of course
  ] u=. rand 3
0.622471 0.324707 0.907825
  ] v=. rand 3
0.0631566 0.38662 0.338598
  u cp v
_0.241038 _0.153432 0.220153
  u cross v
_0.241038 _0.153432 0.220153
   but for arays of vectors
 ] u=. 4 3$rand 12
0.095767 0.601479 0.285658
0.926716 0.299674 0.417604
0.687686 0.837773 0.792088
0.465073 0.605581 0.190086
  ] v=. 4 3$rand 12
0.732158 0.199016 0.654682
0.925557 0.409382 0.619391
0.891663 0.888594 0.716629
  0.9962 0.477721 0.946355
   u cross v
 0.492744 _0.104753  0.277464
 0.418103  _0.36774  0.313855
_0.492744  0.104753 _0.277464
_0.418103   0.36774 _0.313855
   u cp v
| length error: cp
|    u     cp v

How do you generalize this for such arrays (or |:u arrays)?
I often take cross products of millions of vectors as part
of Monte Carlo scattering computations, so it must be fast.

Patrick

On Sat, 8 Feb 2020, R.E. Boss wrote:

 https://code.jsoftware.com/wiki/Phrases/Matrices#Vector_cross_product


 R.E. Boss


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to