vector multiplication .* vs *
Mostrar comentarios más antiguos
I have these two vectors,
u= [ 1 2 -1 2 1]
v=[ -1 0 2 0 1]
why does v*u give me an error, whilst u*v' give me a -2, which is the result of a scalar multiplication?
u and v have the same size, so shouldn't v*u go through?
Thanks in advance.
1 comentario
@Omar A Jiminez: knowing the difference between matrix operations and element-wise operations is critical for being able to use MATLAB properly: not just multiplication, but transpose, division, and power too. You need to read the MATLAB documentation:
Respuesta aceptada
Más respuestas (2)
Shomari Edwards
el 29 de Ag. de 2019
0 votos
24.5 + 64/3.52 + 8.3 · 12.53√
3 76.4−28/15
1 comentario
Walter Roberson
el 29 de Ag. de 2019
It is not clear what you are trying to convey here?
John E Keevil
el 18 de Feb. de 2022
0 votos
The simple answer to the question is:-
u= [ 1 2 -1 2 1] and v=[ -1 0 2 0 1] are both row vectors. You cannot matrix multiply them because the number of rows and columns are not compatible for matrix multiplication. To multiply u*v by matrix multiplication requires the number of rows of u to equal the number of columns of v, which it does not since u has one row and v has 5 columns. To correct that, you have to transpose v, then it has one column. v' is the transpose of v. This why u*v' works.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!