Javascript Array matrixMult(matrix, vector)

Description

Javascript Array matrixMult(matrix, vector)


/*/*from w w w . j a  va  2 s . c om*/
 * matrixMult
 * Multiplies a matrix with a vector
 * @matrix  MxN array
 * @vector  Nx1 array
 * @return  Nx1 array
 */

var matrixMult = function(matrix, vector) {
  
  var i, j;
  var m = matrix.length;
  var n = vector.length;
  var R = new Array(n);
  
  for ( i = 0; i < m; i++ ) {
    R[i] = 0;
    for ( j = 0; j < n; j++ ) {
      R[i] += matrix[i][j] * vector[j];
    }
  }
  return R;
};



PreviousNext

Related