Matlab向量的幅值(大小)

具有元素为v1v2v3...vn的向量v的幅值(大小)由下列公式求出:

采取以下步骤来计算向量的大小 -

  • 以向量的乘积为单位,使用数组乘法(.*)。产生向量sv,向量sv的元素是向量v的元素的平方。即:sv = v.*v;
  • 使用sum函数得到向量v的元素的平方和,也称为向量v的点积。即:dp= sum(sv);
  • 使用sqrt函数得到和的平方根,也是向量v的大小。即:mag = sqrt(s);

例子

使用以下代码创建脚本文件 -

v = [1: 2: 20];
sv = v.* v;      %the vector with elements 
                 % as square of v's elements
dp = sum(sv);    % sum of squares -- the dot product
mag = sqrt(dp);  % magnitude
disp('Magnitude:'); disp(mag);

执行上面示例代码,得到以下结果 -

Magnitude:
 36.469

上一篇: Matlab向量 下一篇: Matlab矩阵