element in matrix multiplication to create a new matrix

6 Ansichten (letzte 30 Tage)
lo
lo am 14 Mär. 2014
Bearbeitet: Marta Salas am 14 Mär. 2014
A and O is 3x1 matrix
B and D is 1x3 matrix
f is a 3x3 matrix
What is wrong with the code below?
i=1:3
j=1:3
T(i,j)=A(i).*B(j).*O(i).*D(j).*f(i,j)

Akzeptierte Antwort

Marta Salas
Marta Salas am 14 Mär. 2014
Bearbeitet: Marta Salas am 14 Mär. 2014
Your code doesn't run because you are using .* which is element wise multiplication instead of standar matrix multiplication. You can do:
for i=1:3
for j=1:3
T(i,j)=A(i).*B(j).*O(i).*D(j).*f(i,j)
end
end
or
T=A*B*O*D*f
depending on the result you are expecting.

Weitere Antworten (1)

Benjamin Avants
Benjamin Avants am 14 Mär. 2014
Your question is a little unclear, but if you want to do matrix multiplication like this:
|d|
|a,b,c| * |e| = (ad+be+fc)
|f|
or this
|a| |ae,af,ag|
|b| * |e,f,g| = |be,bf,bg|
|c| |ce,cf,cg|
then you want to use the normal * operator and not the .* operator.
The .* operator will multiply a constant by each element in the matrix or array. It will also do elementwise multiplication on arrays of the same size.
Example:
|a,b| |e,f| |ae,bf|
|c,d| .* |g,h| = |ag,dh|

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by