如何将矩阵与向量相乘并在矩阵中得到结果?

时间:2019-02-13 07:18:37

标签: matlab octave

假设我有一个矩阵:

A = [ a, b, c;
      d, e, f ];

和向量:

b = [ x;
      y;
      z ];

我想要的是结果矩阵为:

C = [ a*x, b*y, c*z;
      d*x, e*y, f*z ];

我该怎么做? 本质上,我想将矩阵(维度:mxn)与向量(nx1)相乘,并得到结果矩阵mxn。

根据注释的要求(使用八度版本3.8.0):

octave> A = [ 1,2,3;4,5,6]; B=[10;20;30];
octave> A*B
ans =

   140
   320

octave> A.*B
error: product: nonconformant arguments (op1 is 2x3, op2 is 3x1)
octave> bsxfun(@times, A, B)
error: bsxfun: nonconformant dimensions: 2x3 and 3x1

1 个答案:

答案 0 :(得分:1)

A = [ 1,2,3;4,5,6];
B = [10;100;1000];
A.*B.'
ans =

     10    200   3000
     40    500   6000
相关问题