利用matlab进行向量的四则运算
1、加(减)法。同型矩阵直接相加即可。如附图所示,利用randperm函数生成两个个行向量(10个0-100之间的整数作为元素),然后直接相加(减法)即可。


2、若是不同型,则要满足矩阵加(减)法的规则,例如将某个矩阵的所有元素都加1,如附图所示,利用rand函数生成一个4行5列的服从(0,1)的正太分布矩阵,然后*10后,利用floor进行一个取整,最后直接加1即可。

3、乘(除)法。矩阵乘法需满足乘数1的列与乘数2的行相同才行。如果是要元素对应相乘或相除则需要使用点运算符,如附图所示。


1、利用dot函数可以计算两个长度相同的向量的点积;点积:及向量的内积。点积百度百科:http://baike.baidu.com/view/2744555.htm
2、点积函数dot语法:y=dot(A,B,dim)dim指定了计算点积的维度。例子:
a =
1 2
3 4
>> b
b =
1 2
1 2

3、Cross-计算向量叉乘。
cross Vector cross product.
C = cross(A,B) returns the cross product of the vectors
A and B. That is, C = A x B. A and B must be 3 element
vectors.
C = cross(A,B) returns the cross product of A and B along the
first dimension of length 3.
C = cross(A,B,DIM), where A and B are N-D arrays, returns the cross
product of vectors in the dimension DIM of A and B. A and B must
have the same size, and both SIZE(A,DIM) and SIZE(B,DIM) must be 3.
Class support for inputs A,B:
float: double, single
