一、 两个列矢量的内积
对于两个列矢量的内积的计算方法如下:
xdoty = y' * x
代码如下:
>> x = [1,2,3,5]'
x =
1
2
3
5
>> y =[3,6,7,8]'
y =
3
6
7
8
>> xdoty = y'* x
xdoty =
76
>>
对于两个长度相等的实矢量x和y,计算其矢量余弦的方法如下:
cosxy = y' * x / (norm(x) * norm(y))
而对于复矢量,正交性的比较的度量是矢量余弦的模数。如下:
collinearity = abs(y' * x) / (norm(x) * norm(y))
当collinearity 为0时,则表示矢量x和y实质上是正交的。而当collinearity接近为1时,表示矢量x与y接近共线的。
代码实现如下:
>> x = [1 2 4 5]'
x =
1
2
4
5
>> y = [3 6 7 8]'
y =
3
6
7
8
>> cosxy = y'*x/(norm(x) * norm(y))
cosxy =
0.97357773436082
>>
对于复矢量,代码如下:
代码一:
>> x = [2:2:8]'*j
x =
0 + 2.00000000000000i
0 + 4.00000000000000i
0 + 6.00000000000000i
0 + 8.00000000000000i
>> y = [10:2:16]'*j
y =
0 +10.00000000000000i
0 +12.00000000000000i
0 +14.00000000000000i
0 +16.00000000000000i
>> collinearity = abs(y' * x) / ( norm(x) * norm(y) );
>> collinearity = abs(y' * x) / ( norm(x) * norm(y) )
collinearity =
0.96886393162697
>>
代码二:(矢量x与y共线)
>> x = [2:2:8]'*j
x =
0 + 2.00000000000000i
0 + 4.00000000000000i
0 + 6.00000000000000i
0 + 8.00000000000000i
>> y = 2*[2:2:8]'*j
y =
0 + 4.00000000000000i
0 + 8.00000000000000i
0 +12.00000000000000i
0 +16.00000000000000i
>> collinearity = abs(y' * x) / ( norm(x) * norm(y) )
collinearity =
1
>>