/**
 * A driver for programming assignment 1
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class PA1Driver
{
    /**
     * The entry point
     *
     * @param args   The command line arguments
     */
    public static void main(String[] args)
    {
       // Vectors
       // =======

       // Multiplication by a scalar
       {
          double[] p = {5.0, 8.0, 3.0};
          
          double[] z;
          
          z = VMath.times(1.5, p);
          print(z);          
          cr();          
       }
       

       // Addition and subtraction
       {
          double[] r = {0.5, -1.0};
          double[] q = {1.5, -0.5};
          
          double[] z;
          
          z = VMath.sum(q, r);
          print(z);          
          cr();
          
          z = VMath.diff(q, r);
          print(z);          
          cr();          
       }
       

       // Dot product
       {
          double[] r = {2.0, 3.0};
          double[] q = {4.0, 5.0};
          
          print(VMath.dot(q, r));
          cr();          
       }
       

       // Norm
       {
          double[] r = {2.0, 3.0, -7.0, 1.0};
          
          print(VMath.norm(r));          
          cr();          
       }
       

       // Normalized
       {
          double[] r = {3.0, 4.0};
          
          double[] z;

          z = VMath.normalized(r);          
          print(z);
          cr();          
       }
       

       // Perp
       {
          double[] r = {3.0, 4.0};
          
          double[] z;

          z = VMath.perp(r);          
          print(z);
          cr();          
       }


       // Matrices
       // ========

       // Transpose
       {
          double[][] a = {{ 5.0, 1.0, 3.0},
                          { 8.0, 9.0, 7.0},
                          { 6.0, 6.0, 2.0},
                          { 5.0, 8.0, 4.0}
                         };

          print(MMath.transpose(a));          
          cr();          
       }
       

       // Addition
       {
          double[][] a = {{ 4.0, 9.0},
                          { 2.0, 1.0}
                         };
       
          double[][] b = {{ 6.0, 8.0},
                          { 1.0, 3.0}
                         };
       
          double[][] z;
          
          z = MMath.sum(a, b);          
          print(z);       
          cr();          
       }
       
       

       // Multiplication by a vector
       {
          double[][] m = {{ 4.0, 9.0},
                          { 2.0, 1.0},
                          { 7.0, 5.0},
                          { 8.0,-1.0}
                         };
       
          double[]   v = { 6.0, 8.0, 3.0, 1.8};
       
          double[]   z;
          
          z = MMath.times(v, m);          
          print(z);       
          cr();          
       }
       
       

       // Multiplication
       {
          double[][] a = {{ 4.0, 9.0},
                          { 2.0, 1.0},
                          { 7.0, 5.0},
                          { 8.0,-1.0}
                         };

          double[][] b = {{ 3.0, 6.0,-2.0},
                          {-2.0,-8.0, 5.1}
                         };
       
       
          double[][] z;
          
          z = MMath.times(a, b);          
          print(z);       
          cr();          
       }
       



       // Determinant
       {
          double[][] b = {{ 1.0, 5.0},
                          { 0.0, 1.0}
                         };
       
          print(MMath.det(b));       
          cr();          

          double[][] a = {{ 4.0, 0.0, 0.0},
                          {-1.0, 4.0, 4.0},
                          { 0.1,-0.1, 0.1}
                         };
       
          print(MMath.det(a));          
          cr();          
       }
    }




    /**
     * Print a carriage return
     */
    private static void cr()
    {
       System.out.println();       
    }
    

    /**
     * Print a double
     */
    private static void print(double d)
    {
       System.out.printf("%6.2f",d);       
       System.out.println();       
    }
    


    /**
     * Print a vector
     */
    private static void print(double[] p)
    {
       System.out.printf("(%6.2f",p[0]);       
       for (int i=1; i<p.length; i++)
       {
          System.out.printf(", %6.2f",p[i]);          
       }
       System.out.println(")");       
    }
    

    /**
     * Print a matrix
     */
    private static void print(double[][] m)
    {
       for (int i=0; i<m.length; i++)
       {
          print(m[i]);          
       }
    }
    

}
