UNB/ CS/ David Bremner/ teaching/ java/ Vproduct.java
import ccj.*;

public class Vproduct
{  public static void main(String[] args)
   {  double[][] m = new double[3][3];
      m[0][0] = 1; m[0][1] = 2; m[0][2] = 3;
      m[1][0] = 0; m[1][1] = 1; m[1][2] = -1;
      m[2][0] = 2; m[2][1] = 1; m[2][2] = 0;

      double[] v = new double[3];
      v[0] = 4; v[1] = 5; v[2] = 6;

      double[] r = vproduct(m, v);

      int i;
      for (i = 0; i < r.length; i++)
         System.out.println(r[i]);
   }

   public static double[] vproduct(double[][] a, double[] v)
   {  double[] r = new double[a.length];


      int i;
      for (i = 0; i < a.length; i++)
      {  if (a[i].length != v.length)
            throw new IllegalArgumentException();
         int k;
         double sum = 0;
         for (k = 0; k < v.length; k++)
            sum = sum + a[i][k] * v[k];
         r[i] = sum;
      }
      return r;
   }


}