Package ucar.ma2

Class MAVector

java.lang.Object
ucar.ma2.MAVector

public class MAVector extends Object
Abstraction for vector operations. A vector is a rank-1 Array. All operations done in double precision
  • Constructor Summary

    Constructors
    Constructor
    Description
    MAVector(double[] values)
    Create an MAVector out of a double array
    MAVector(int nelems)
    Create an MAVector of the given length.
    Create an MAVector using the given rank-1 array.
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a new MAVector that is the same as this one, with a copy of the backing store.
    double
    Cos between two vectors = dot(v) / norm() * norm(v)
    double
    Dot product of 2 vectors
    double
    getDouble(int i)
     
    int
     
    double
    Get the L2 norm of this vector.
    void
    Normalize this vector, so it has norm = 1.0.
    void
    setDouble(int i, double val)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MAVector

      public MAVector(double[] values)
      Create an MAVector out of a double array
    • MAVector

      public MAVector(int nelems)
      Create an MAVector of the given length.
    • MAVector

      public MAVector(Array a)
      Create an MAVector using the given rank-1 array.
      Parameters:
      a - rank-1 array
      Throws:
      IllegalArgumentException - is a is not rank 1
  • Method Details

    • getNelems

      public int getNelems()
    • getDouble

      public double getDouble(int i)
    • setDouble

      public void setDouble(int i, double val)
    • copy

      public MAVector copy()
      Create a new MAVector that is the same as this one, with a copy of the backing store.
    • cos

      public double cos(MAVector v)
      Cos between two vectors = dot(v) / norm() * norm(v)
      Parameters:
      v - cosine with this vector
      Returns:
      double result: cos between this and v
      Throws:
      IllegalArgumentException - if nelems != v.getNelems().
    • dot

      public double dot(MAVector v)
      Dot product of 2 vectors
      Parameters:
      v - dot product with this vector
      Returns:
      double result: dot product
      Throws:
      IllegalArgumentException - if nelems != v.getNelems().
    • norm

      public double norm()
      Get the L2 norm of this vector.
      Returns:
      double norm
    • normalize

      public void normalize()
      Normalize this vector, so it has norm = 1.0.