MATLAB: Vector multiplication .* vs *

arraybasic operationselementerrormultiplicationoperations

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.

Best Answer

v*u is algebraic matrix multiplication, for which the rule is that for an (M x N) * (P x Q) operation, that N must equal P and the output size is M x Q -- so (M x N) * (N x Q) giving M x Q. You have (1 x 5) * (1 x 5) which violates that rule. When you take u * v' then you have (1 x 5) * (5 x 1) giving 1 x 1.
v.*u would go element by element, result(K) = v(K) * u(K) which would be 1 x 5 result.