如何将矩阵与向量相乘并在矩阵中得到结果?
How do I multiply matrix with vector and get result in matrix?
假设我有一个矩阵:
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
A = [ 1,2,3;4,5,6];
B = [10;100;1000];
A.*B.'
ans =
10 200 3000
40 500 6000
假设我有一个矩阵:
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
A = [ 1,2,3;4,5,6];
B = [10;100;1000];
A.*B.'
ans =
10 200 3000
40 500 6000