Excel中的交叉产品的VBA
似乎由于某种原因,Excel程序员select省略任何向量跨产品function。
而且,在网上看,没有太多的需求。 虽然excel是做线性代数的有力工具。
我需要一个VBA脚本来做vector交叉产品。 而我唯一能find的就是这里:
https://www.excelbanter.com/excel-worksheet-functions/209233-how-do-you-use-visual-basic-find-cross-product-two-vectors.html
-------------------- Function vCP(v1 As Variant, v2 As Variant) As Variant vCP = Array(v1(2) * v2(3) - v1(3) * v2(2), _ v1(3) * v2(1) - v1(1) * v2(3), _ v1(1) * v2(2) - v1(2) * v2(1)) End Function --------------------
使用它很简单,
- select3个水平相邻的单元格,input公式
-
=vCP(
- select在3个连续的水平或垂直单元格中的vectorA(在A×B中)
- types
,
- select向量B,它是垂直单元的3个连续水平
- types
)
- 按下Ctrl + Shift + Enter
我做了一些testing,它可以工作,但是它输出水平向量,而不是垂直线性代数。
有谁知道如何改变这个脚本,以便3Dvector可以垂直输出?
有没有更好的方式在Excel中获得交叉产品?
感谢:D
使用Application.Transpose:
Function vCP(v1 As Variant, v2 As Variant) As Variant vCP = Application.Transpose(Array(v1(2) * v2(3) - v1(3) * v2(2), _ v1(3) * v2(1) - v1(1) * v2(3), _ v1(1) * v2(2) - v1(2) * v2(1))) End Function