Re: Cross Product

From: Carl J. Schreck, III <carl_at_nyahnyahspammersnyahnyah>
Date: Thu, 11 Sep 2008 09:59:38 -0400

Hi All,

Sorry for mixing up my linear algebra terms. I think what I'm looking
for is an "outer product"
(http://en.wikipedia.org/wiki/Outer_product), essentially the same as
the Kronecker product that Travis mentions. "Inner products" are the
same as "dot products", but I mistakenly thought that cross and outer
were also the same (cross involves the determinant).

In any case, what Andrew shows is what I was looking for. Another,
but equally clumsy, method would be:

  outer = new( (/ dimsizes(a), dimsizes(b) /), integer )
  a2d = conform( outer, a, 0 )
  b2d = conform( outer, b, 1 )
  outer = a2d * b2d

By contrast, in matlab it would simply be:

  outer = a' * b

But of course enough other things are so much easier in ncl that I
won't complain too loudly!

      Thanks,
      Carl

On Wed, Sep 10, 2008 at 10:18 PM, Andrew Mai <mai_at_ucar.edu> wrote:
> Carl J. Schreck, III wrote:
>
> Is there a built-in way to do a cross product in ncl? For example, if
> you have an array of length m and another of length n, it would return
> a matrix that's m x n? I see dot products mentioned in the
> documentation for matrix multiply (#), but no cross product.
>
>
> The following simple example program shows how to do what you want, albeit a
> bit clumsily. Note that it does use the matrix multiply operator.
>
> ; Example of cross product: C = A x B
>
> begin
>
> a = (/1,2,3,4/)
> b = (/5,6,7/)
> a1 = new((/dimsizes(a),1/),double)
> b1 = new((/1,dimsizes(b)/),double)
> a1(:,0) = a
> b1(0,:) = b
> c = a1 # b1
> print(c)
>
> end
>
>
> The output is:
>
> Copyright (C) 1995-2007 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.0.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> Variable: c
> Type: double
> Total Size: 96 bytes
> 12 values
> Number of Dimensions: 2
> Dimensions and sizes: [4] x [3]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : -9999
> (0,0) 5
> (0,1) 6
> (0,2) 7
> (1,0) 10
> (1,1) 12
> (1,2) 14
> (2,0) 15
> (2,1) 18
> (2,2) 21
> (3,0) 20
> (3,1) 24
> (3,2) 28
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Sep 11 2008 - 07:59:38 MDT

This archive was generated by hypermail 2.2.0 : Fri Sep 12 2008 - 21:42:04 MDT