Detailed explanation of the cross product calculation process of matlab cross() function

vector cross product


Mathematically, the cross product of two vectors is a vector that passes through the intersection of two intersecting vectors and is perpendicular to the plane of the two vectors. In Matlab, use the function cross to realize.

function cross()

Format C = cross(A,B) % If A and B are vectors, return the cross product of A and B, that is, C=A×B, A and B must be vectors of 3 elements; if A and B are matrices , returns a 3×n matrix, where the columns are the cross products of the corresponding columns of A and B, and both A and B are 3×n matrices.

C = cross(A,B,dim) % gives the cross product of vectors A and B in dimension dim. A and B must have the same dimension, size(A,dim) and size(B,dim) must be 3.
 

Vector multiplication of 1 row and 3 columns

Computes the outer product (cross product) of vectors. (x1,y1,z1)×(x2,y2,z2)=(y1z2-y2z1,z1x2-z2x1,x1y2-x2y1)

>> a=[0,0,1];  
>> b=[0,2,0];  
>> c=cross(a,b)    %计算向量a与b的外积  
c =  
    -2     0     0  

 If it is a matrix of type 3x3, 5x3, how to cross multiply it

It is the principle of empathy. Three 1-row and 3-column vectors form 3x3, then the calculation formula of the cross product is the same as above.

A=\begin{bmatrix} x1,y1,z1\\ a1,b1,c1 \end{bmatrix}

 B=\begin{bmatrix} x2,y2,z2\\ a2,b2,c2 \end{bmatrix}

cross(A,B)=\begin{bmatrix} y1*z2-y2*z1 ,z1*x2-z2*x1 ,x1*y2-x2*y1 \\ b1*c2-b2*c1 ,c1*a2-c2*a1 ,a1*b2-a2*b1 \end{bmatrix}

By analogy, the multiplication of 3X3 matrix and 4X3 matrix is ​​the same.

Example:

1x3

a =

     1     2     3

>> b=[3,4,5]

b =

     3     4     5

>> cross(a,b)

ans =

    -2     4    -2

>> 

2x3 matrix

a2 =

     1     2     3
     2     3     4

>> b2=[3,4,5;4,5,6]

b2 =

     3     4     5
     4     5     6

>> cross(a2,b2)

ans =

    -2     4    -2
    -2     4    -2

Guess you like

Origin blog.csdn.net/Vertira/article/details/131827450