element in matrix multiplication to create a new matrix

5 visualizaciones (últimos 30 días)
lo
lo el 14 de Mzo. de 2014
Editada: Marta Salas el 14 de Mzo. de 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)

Respuesta aceptada

Marta Salas
Marta Salas el 14 de Mzo. de 2014
Editada: Marta Salas el 14 de Mzo. de 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.

Más respuestas (1)

Benjamin Avants
Benjamin Avants el 14 de Mzo. de 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|

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by