How do I multiply matrices having elements as vectors?

2 visualizaciones (últimos 30 días)
Sameer
Sameer el 2 de Jun. de 2015
Comentada: Adam el 2 de Jun. de 2015
A*B doesn't work A.*B doesn't work either since it multiplies them element by element
  3 comentarios
Sameer
Sameer el 2 de Jun. de 2015
Editada: Sameer el 2 de Jun. de 2015
a=1:1000;
A=[a 2*a;a 2*a];
B=[2*a a;a a];
C=A*B %Error using *
%Inner matrix dimensions must agree.
D= A.*B % multiplies element by element which I don't want
Adam
Adam el 2 de Jun. de 2015
So what is your expected result?

Iniciar sesión para comentar.

Respuestas (1)

Matthew Eicholtz
Matthew Eicholtz el 2 de Jun. de 2015
If I understand the question correctly, you are asking how to multiply two vectors of the same size.
Without loss of generality, let's assume A and B are 1x10 vectors. A*B will not work because the inner dimensions do not match (1x10 * 1x10). A.*B will only multiply each pair of elements as you noticed, yielding a 1x10 result.
Two potential solutions:
  1. dot(A,B)
  2. A*B'

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by