首页 > 编程知识 正文

三维向量的向量积公式,n维向量内积算法

时间:2023-05-05 00:32:27 阅读:248783 作者:2068

在三维空间中,两个向量的乘积(向量积,外积,乘积,区别于两个向量的数乘:内积,点积)表示两个向量的扭矩,而三个向量的混合积A×B·C,则表示由三个向量A,B,C所构成的平行六面体的面积。而且在混合积中A,B,C的位置是可以互换的(这个很容易证明),这也符合我们的经验。那么问题来了?
1)3个或者N>3个三维向量相乘如何定义?A×B×C×D....因为A×B是有定义的,A×B是向量,那么只要继续乘就可以了,这也说明3维向量相乘,向量个数不是问题;
2)向量个数不是问题,那4维向量的两个向量相乘呢?

设A=(a1,a2,a3,a4),B=(b1,b2,b3,b4) A*B=(x1,x2,x3,x4)则满足如下方程组:
 ① A·(A*B)=0
 ② B·(A*B)=0
 ③ |A*B|=|A|*|B|sinθ。
这是一个4元二次方程组,但只有3个方程组,显然解不是一个。这说明A*B在4维空间,如果按垂直来定义,无法唯一确定,其结果是一个面(受限的)。
类似的,扩展到n维空间,方程组还是只有3个。结果是n-2维体(面)(受限于方程)。

下面推广n维向量的
n-1个向量积:A1*A2*...A(n-1)·;
混合积:A1*A2*...A(n-1)·An.


/// <summary> /// 向量积 /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public static TVector Mul(TVector A, TVector B) { if (A.Count == B.Count && B.Count == 3) { var theI = A[1] * B[2] - A[2] * B[1]; var theJ = -(A[0] * B[2] - A[2] * B[0]); var theK = A[0] * B[1] - A[1] * B[0]; TVector theV = new TVector(theI, theJ, theK); return theV; } else { throw new Exception("现仅支持3分量."); } } /// <summary> /// n维向量的n-1个向量的乘积,n>3 /// </summary> /// <param name="Vectors">向量组</param> /// <returns></returns> public static TVector Mul2(params TVector[] Vectors) { if (Vectors==null || Vectors.Length < 2) { throw new Exception("参数错误必须是n维向量n-1个向量模式"); } var theN = Vectors[0].Count; if (theN != Vectors.Length + 1) { throw new Exception("参数错误必须是n维向量n-1个向量模式"); } var theA = new double[theN, theN]; for (int i = 0; i < theN; i++) { theA[0, i] = 1; } for (int i = 0; i < theN; i++) { for (int j = 0; j < Vectors.Length; j++) { theA[j + 1, i] = Vectors[j][i]; } } //按第一行展开求代数余子式,并计算行列式.(1,j)的代数余子式就是所求向量第j个分量的值. var theRetA = new double[theN]; for (int j = 0; j < theN; j++) { var theA1 = LinearAlgebra.GetDeterminantMij(theA, 1, j + 1); var theSign = LinearAlgebra.CalcDeterMijSign(1, j + 1); theRetA[j] = theSign * LinearAlgebra.CalcDeterminant(theA1); } return new TVector(theRetA); } /// <summary> /// n维向量的n个向量的混合积A1×A2.....An-1·An /// </summary> /// <param name="Vectors">向量组</param> /// <returns></returns> public static double Mul3(params TVector[] Vectors) { if (Vectors == null || Vectors.Length < 2) { throw new Exception("参数错误必须是n维向量n-1个向量模式"); } var theN = Vectors[0].Count; if (theN != Vectors.Length) { throw new Exception("参数错误必须是n维向量n个向量模式"); } var theA = new double[theN, theN]; for (int i = 0; i < theN; i++) { for (int j = 0; j < Vectors.Length; j++) { theA[j, i] = Vectors[j][i]; } } return LinearAlgebra.CalcDeterminant(theA); } /// <summary> /// 向量混合积A×B·C /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public static double Mul(TVector A, TVector B, TVector C) { if (A.Count == B.Count && B.Count == 3) { double[,] theA = new double[3, 3]; for (int i = 0; i < 2; i++) { theA[0, i] = A[i]; theA[1, i] = B[i]; theA[2, i] = C[i]; } return LinearAlgebra.CalcDeterminantAij(theA); } else { throw new Exception("现仅支持3分量."); } }

暂时研究到此,后面有时间继续研究。 注意:算法中用到的函数参见Mymathlib系列.
后记:N维空间中(N>3)的两个向量相乘,如果按照三维空间中的向量积的定义方式,往往得不到唯一的积向量,对于大于三维的空间,不好获得直观的看法。我们不换假设在平面上有一条线A,另一条线B与之垂直,如果B的模确定,则B是确定的,但如果是三维空间,则满足与A垂直且模一定的线段,就不止一条了,而是一个圆。那么在4维空间中,对于A*B,满足向量积定义的向量也不是唯一的。 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。