Excel MMULT on MATLAB for different matrix dimensions.

4 ビュー (過去 30 日間)
Jose Rodriguez
Jose Rodriguez 2021 年 10 月 16 日
編集済み: dpb 2021 年 10 月 16 日
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. :)
  1 件のコメント
Jose Rodriguez
Jose Rodriguez 2021 年 10 月 16 日
Thank you for your consice answer it works great.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by