Q:

Write a JavaScript program to create the dot products of two given 3D vectors

0

Write a JavaScript program to create the dot products of two given 3D vectors. 
Note: The dot product is the sum of the products of the corresponding entries of the two sequences of numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function dot_product(vector1, vector2) {
  var result = 0;
  for (var i = 0; i < 3; i++) {
    result += vector1[i] * vector2[i];
  }
  return result;
}
console.log(dot_product([1,2,3], [1,2,3]))
console.log(dot_product([2,4,6], [2,4,6]))
console.log(dot_product([1,1,1], [0,1,-1]))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now