将矩阵的最后一行与不同顺序的变量相乘

时间:2016-08-15 07:55:00

标签: matlab matrix

我想将矩阵的最后一行与不同顺序的变量相乘;

%A matrix
          N = length(a)-1;% order of the matrix
           last_row = (a(1:end-1))*(1/a(end));% creating the last row
          k = ones(1,N-1);
          A = diag(k,1) ; % diag(vector, k) produce a matrix filled with zero's and k'th off diagonal as vector, in this  case, 1's.
           last_row = (wc.^(N:-1:1)).*last_row;% multiply the variable with different order.
           A(end,:) = last_row;% adding the last_row

之前我将变量乘以我的" last_row"

last_row =
      1.0000    2.6131    3.4142    2.6131

我的矩阵:

A =
       0     1     0     0
       0     0     1     0
       0     0     0     1
       0     0     0     0
将变量乘以后

last_row =
    1.0e+009 *
      1.2624    0.0175    0.0001    0.0000

当我插入最后一行时:

A =
    1.0e+009 *
           0    0.0000         0         0
           0         0    0.0000         0
           0         0         0    0.0000
      1.2624    0.0175    0.0001    0.0000

它正在改变不是我的last_row的元素,我在哪里出错。所有这些1都应该保持原样

1 个答案:

答案 0 :(得分:0)

如果计算正确,则仅更改结果矩阵的最后一行。当MATLAB格式化输出时,MATLAB会尝试计算矩阵的所有数字 所以简而言之,没有问题。例如,检查A(1,2)是否为1 如果您需要不同的格式,请查看formatsprintf