Excel MMULT on MATLAB for different matrix dimensions.

6 次查看(过去 30 天)
I'm trying to replicate the formula MMULT from Excel into MATLAB.
The two matrixes have different dimensions 4 x 1 and 4 x 4. Returning a product of 4 x 1
Below is an example in Excelusing MMULT
x =
Below is the MATLAB function trying to replica the above example.
The function returns C a 4 x 4 matrix when I need a 4 x 1 matrix from the product of RR times A in excel.
Thank You.
  1 个评论
Stephen23
Stephen23 2021-10-16
编辑:Stephen23 2021-10-16
"I'm trying to replicate the formula MMULT from Excel into MATLAB."
Matrix multiplication is a very basic mathematical operation that has existed in MATLAB for the last forty years:
Is there a particular reason why you cannot use the inbuilt function?

请先登录,再进行评论。

采纳的回答

dpb
dpb 2021-10-16
编辑:dpb 2021-10-16
MATLAB being defined as the MATrix LABoratory follows conventional matrix algebra rules --
>> A=[0.29;-1.55;2.09;0.782];
>> R=[4/3 2/3 0 0;2/3 4/3 0 0;0 0 4/3 -2/3;0 0 -2/3 4/3];
>> C=R*A
C =
-0.6467
-1.8733
2.2653
-0.3507
>>
Arrays A, B are only conformable for matrix multiplication C=AB if size(A,2) == size(B,1) (number rows in B is same as number of columns in A). The size of the output array C is then size(A,1) x size(B,2).
If R is 4x4 and A 4x1, then R*A --> 4x4 * 4x1 --> 4x1
Your code above uses the "dot" operator .* which is element-wise multiplication and MATLAB silently expanded the vector to the size of the array to produce the 4x4 result.
As the above shows, all you need is the matrix multiplication operator * applied to the two variables to produce the desired result; the same as Excel implements in a much more convenient format/syntax. :)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by