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 Wed Sep 10 2008 - 20:18:25 MDT
This archive was generated by hypermail 2.2.0 : Fri Sep 12 2008 - 21:42:04 MDT