Article ID: 121820
Article Last Modified on 10/11/2006
i j k
=========
c = a x b = m n o = [(n*z)-(o*y)]i - [(o*x)-(m*z)]j + [(m*y)-(n*x)]k
x y z
For example, given two vectors a and b:
a = (1,2,3) b = (4,5,6)vector c can be computed:
c = [(2*6)-(3*5)]i - [(3*4)-(1*6)]j + [(1*5)-(2*4)]k
= [12-15]i - [12-6]j + [5-8]k
= [-3]i - [6]j + [-3]k
= (-3,6,-3)
In Microsoft Excel, you can create a Visual Basic function to perform
these calculations and return the results into an array.
' The following line must be placed at beginning of module:
Option Base 1
' Returns the cross product of the two input vectors.
Function Cross_Product_VBA(Vec1 As Object, Vec2 As Object) As Variant
' TempArray is a temporary variable to store the cross product.
Dim TempArray(3, 1)
' The following lines put elements of the product into TempArray.
TempArray(1, 1) = Vec1.Cells(2, 1).Value * _
Vec2.Cells(3, 1).Value - Vec1.Cells(3, 1).Value * _
Vec2.Cells(2, 1).Value
TempArray(2, 1) = Vec1.Cells(3, 1).Value * _
Vec2.Cells(1, 1).Value - Vec1.Cells(1, 1).Value * _
Vec2.Cells(3, 1).Value
TempArray(3, 1) = Vec1.Cells(1, 1).Value * _
Vec2.Cells(2, 1).Value - Vec1.Cells(2, 1).Value * _
Vec2.Cells(1, 1).Value
' Assigns the TempArray variable to Cross_Product_VBA.
Cross_Product_VBA = TempArray
End Function
Be sure to select three vertical cells before typing the function, and
enter the function as an array formula by pressing CTRL+SHIFT+ENTER or
COMMAND+RETURN. For example, given the ranges A1:A3 (vector a) and B1:B3
(vector b), calculate the cross product by highlighting C1:C3, type the
following function, and press CTRL+SHIFT+ENTER or COMMAND+RETURN:
=Cross_Product_VBA(A1:A3,B1:B3)
A1: 1 B1: 4 C1: -3 A2: 2 B2: 5 C2: 6 A3: 3 B3: 6 C3: -3
Additional query words: XL98 XL97 XL7 XL5 XL
Keywords: kbdtacode kbhowto kbprogramming KB121820