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. :)

추가 답변 (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