Malfunction to my matrix calculation

조회 수: 3 (최근 30일)
Vic
Vic 2022년 10월 27일
편집: James Tursa 2022년 10월 27일
Below here, I want to calculate the matrix of X.
From what I understand, K is a 4x4 matrix, and F is a 1x4 matrix.
In order to get X, I have to transpose my martix F, so it can be a 4x1 matrix.
Therefore, X should be a 4x1 matrix.
The problem here is what I get instead is a 4x4 matrix, which can be shown in the second picture below.
Is there a typo problem or something that I didn't notice about the code?

채택된 답변

James Tursa
James Tursa 2022년 10월 27일
편집: James Tursa 2022년 10월 27일
K .* F (with the dot) does element-wise multiplication with implicit array expansion if the variables are different sizes, thus the 4x4 result.
K * F (without the dot) does matrix multiply and will get a 4x1 result.
E.g.,
K = rand(4,4); % 4x4
F = rand(1,4); % 1x4
K = inv(K); % 4x4
F = F'; % 4x1
K .* F % the 4x1 is implicitly expanded to 4x4 for this element-wise operation
ans = 4×4
-0.2635 0.3232 0.0993 -0.4084 -0.6048 -0.5805 1.1160 0.2753 3.4958 -2.9911 -2.9084 6.3079 -0.1182 0.2026 0.2726 -0.5389
K * F % a normal matrix multiply
ans = 4×1
1.2976 1.6914 -2.6004 1.0808

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by