Effacer les filtres
Effacer les filtres

Dot Product of row vectors using loops not functions

8 vues (au cours des 30 derniers jours)
Jonathan Lam
Jonathan Lam le 26 Jan 2022
Modifié(e) : Torsten le 26 Jan 2022
I'm struggling to code the function of a dot product using only loops. Vector a1= [1 1 1] and a2=[2 2 2] and I understand the dot product is 6, but my resultant vector is [2 2 2] when I need it to be 6. Any thoughts?
  1 commentaire
Torsten
Torsten le 26 Jan 2022
Modifié(e) : Torsten le 26 Jan 2022
Without any MATLAB functions:
result = 0;
for i=1:col1
result = result + a1(i)*a2(i);
end

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by