How to use for loop structure to calculate two vectors to dot product

34 visualizaciones (últimos 30 días)
Shuming Ye
Shuming Ye el 20 de Feb. de 2021
Comentada: Matt J el 20 de Feb. de 2021
How to use for loop structure to calculate two vectors to dot product.
Please give an example.

Respuestas (1)

William
William el 20 de Feb. de 2021
a = 1:5;
b = 6:10;
c = 0;
for j = 1:5
c = c + a(j)*b(j);
end
However, this calculation can be done more simply with the dot() function:
c = dot(a,b);
or with the expression:
c = sum(a.*b);

Categorías

Más información sobre Logical 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