How to multiply each term in a n*n matrix with elements in a column matrix

1 vue (au cours des 30 derniers jours)
ASHA PON
ASHA PON le 1 Déc 2022
Commenté : ASHA PON le 1 Déc 2022
I am having a 14*15 matrix and 15*1 matrix. Now, I need to multiply these two matrix. Thank you in advance.
For example:
A=[ 0.34005, 1.15985, -1.42862; 0.45204, -0.12963, -0.07851; 0.18586, -0.49792, 0.56187; 0.20188, 0.19786, -0.54699]
B=[0; 0; 1; 1]
Expected output:
A11 - First row first column, A21 - Second row first column
C=[A11*B2, A21*B3, A31*B4; A12*B1, A22*B3, A32*B4; A13*B1, A23*B2, A33*B4; A14*B1, A24*B2, A34*B3]
C=[0, 1.15985, -1.42862; 0, -0.12963, -0.07851; 0, 0, 0.56187; 0, 0, -0.54699]
  3 commentaires
John D'Errico
John D'Errico le 1 Déc 2022
Confusing. You seem to be mixing up rows and columns, sort of randomly. In your words, you talk about a matrix with 14 rows and 15 columns. But your example has more rows than columns in A. But then the way you then show the indexes for A, it has more columns than rows. Perhaps you don't understand how MATLAB treats arrays.
A = reshape(1:12,4,3)
A = 4×3
1 5 9 2 6 10 3 7 11 4 8 12
A is a 4x3 matrix. It has 4 rows, and 3 columns. The FIRST index of A is the row number. The second index refers to the column number. So in MATLAB for this matrix, A(1,2) == 5.
ASHA PON
ASHA PON le 1 Déc 2022
Thank you for your reply. Actually i have explained my problem in a smaller matrix dimension for better understanding.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 1 Déc 2022
A=[ 0.34005, 1.15985, -1.42862; 0.45204, -0.12963, -0.07851; 0.18586, -0.49792, 0.56187; 0.20188, 0.19786, -0.54699] ;
B=[0; 0; 1; 1] ;
% A11 - First row first column, A21 - Second row first column
% C=[A11*B2, A21*B3, A31*B4; A12*B1, A22*B3, A32*B4; A13*B1, A23*B2, A33*B4; A14*B1, A24*B2, A34*B3]
C=[0, 1.15985, -1.42862; 0, -0.12963, -0.07851; 0, 0, 0.56187; 0, 0, -0.54699] ;
b = zeros(length(B)-1) ;
for i = 1:length(B)-1
t = B' ;
t(i) =[] ;
b(i,:) = t ;
end
iwant = A*b
  1 commentaire
ASHA PON
ASHA PON le 1 Déc 2022
Thank you for your reply. I am facing dimension error with this code.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by