Class Vectors


  • public final class Vectors
    extends java.lang.Object
    This class consists exclusively of static vector utility methods.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Vectors()
      Private constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double checkedNorm​(double norm)
      Throws an IllegalArgumentException if the given norm value is not real (ie, not NaN or infinite) or zero.
      static double checkedNorm​(Vector<?> vec)
      Returns the vector's norm value, throwing an IllegalArgumentException if the value is not real (ie, not NaN or infinite) or zero.
      static java.lang.IllegalArgumentException illegalNorm​(double norm)
      Return an exception indicating an illegal norm value.
      static boolean isRealNonZero​(double value)
      Returns true if the given value is real (ie, not NaN or infinite) and not equal to zero.
      static double linearCombination​(double a1, double b1, double a2, double b2)
      Compute the linear combination \(a_1 b_1 + a_2 b_2 \) with high accuracy.
      static double linearCombination​(double a1, double b1, double a2, double b2, double a3, double b3)
      Compute the linear combination \(a_1 b_1 + a_2 b_2 + a_3 b_3 \) with high accuracy.
      static double norm​(double x)
      Get the L2 norm (commonly known as the Euclidean norm) for the vector with the given components.
      static double norm​(double x1, double x2)
      Get the L2 norm (commonly known as the Euclidean norm) for the vector with the given components.
      static double norm​(double x1, double x2, double x3)
      Get the L2 norm (commonly known as the Euclidean norm) for the vector with the given components.
      static double normSq​(double x)
      Get the square of the L2 norm (also known as the Euclidean norm) for the vector with the given components.
      static double normSq​(double x1, double x2)
      Get the square of the L2 norm (also known as the Euclidean norm) for the vector with the given components.
      static double normSq​(double x1, double x2, double x3)
      Get the square of the L2 norm (also known as the Euclidean norm) for the vector with the given components.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Vectors

        private Vectors()
        Private constructor.
    • Method Detail

      • isRealNonZero

        public static boolean isRealNonZero​(double value)
        Returns true if the given value is real (ie, not NaN or infinite) and not equal to zero.
        Parameters:
        value - the value to test
        Returns:
        true if value is not NaN, infinite, or zero; otherwise false
      • checkedNorm

        public static double checkedNorm​(double norm)
        Throws an IllegalArgumentException if the given norm value is not real (ie, not NaN or infinite) or zero. The argument is returned to allow this method to be called inline.
        Parameters:
        norm - vector norm value
        Returns:
        the validated norm value
        Throws:
        java.lang.IllegalArgumentException - if the given norm value is NaN, infinite, or zero
      • checkedNorm

        public static double checkedNorm​(Vector<?> vec)
        Returns the vector's norm value, throwing an IllegalArgumentException if the value is not real (ie, not NaN or infinite) or zero.
        Parameters:
        vec - vector to obtain the real, non-zero norm of
        Returns:
        the validated norm value
        Throws:
        java.lang.IllegalArgumentException - if the vector norm value is NaN, infinite, or zero
      • illegalNorm

        public static java.lang.IllegalArgumentException illegalNorm​(double norm)
        Return an exception indicating an illegal norm value.
        Parameters:
        norm - illegal norm value
        Returns:
        exception indicating an illegal norm value
      • norm

        public static double norm​(double x)
        Get the L2 norm (commonly known as the Euclidean norm) for the vector with the given components. This corresponds to the common notion of vector magnitude or length and is defined as the square root of the sum of the squares of all vector components.
        Parameters:
        x - vector component
        Returns:
        L2 norm for the vector with the given components
        See Also:
        L2 Norm
      • norm

        public static double norm​(double x1,
                                  double x2)
        Get the L2 norm (commonly known as the Euclidean norm) for the vector with the given components. This corresponds to the common notion of vector magnitude or length and is defined as the square root of the sum of the squares of all vector components.
        Parameters:
        x1 - first vector component
        x2 - second vector component
        Returns:
        L2 norm for the vector with the given components
        See Also:
        L2 Norm
      • norm

        public static double norm​(double x1,
                                  double x2,
                                  double x3)
        Get the L2 norm (commonly known as the Euclidean norm) for the vector with the given components. This corresponds to the common notion of vector magnitude or length and is defined as the square root of the sum of the squares of all vector components.
        Parameters:
        x1 - first vector component
        x2 - second vector component
        x3 - third vector component
        Returns:
        L2 norm for the vector with the given components
        See Also:
        L2 Norm
      • normSq

        public static double normSq​(double x)
        Get the square of the L2 norm (also known as the Euclidean norm) for the vector with the given components. This is equal to the sum of the squares of all vector components.
        Parameters:
        x - vector component
        Returns:
        square of the L2 norm for the vector with the given components
        See Also:
        norm(double)
      • normSq

        public static double normSq​(double x1,
                                    double x2)
        Get the square of the L2 norm (also known as the Euclidean norm) for the vector with the given components. This is equal to the sum of the squares of all vector components.
        Parameters:
        x1 - first vector component
        x2 - second vector component
        Returns:
        square of the L2 norm for the vector with the given components
        See Also:
        norm(double, double)
      • normSq

        public static double normSq​(double x1,
                                    double x2,
                                    double x3)
        Get the square of the L2 norm (also known as the Euclidean norm) for the vector with the given components. This is equal to the sum of the squares of all vector components.
        Parameters:
        x1 - first vector component
        x2 - second vector component
        x3 - third vector component
        Returns:
        square of the L2 norm for the vector with the given components
        See Also:
        norm(double, double, double)
      • linearCombination

        public static double linearCombination​(double a1,
                                               double b1,
                                               double a2,
                                               double b2)
        Compute the linear combination \(a_1 b_1 + a_2 b_2 \) with high accuracy.
        Parameters:
        a1 - first factor of the first term
        b1 - second factor of the first term
        a2 - first factor of the second term
        b2 - second factor of the seconf term
        Returns:
        linear combination.
        See Also:
        Sum
      • linearCombination

        public static double linearCombination​(double a1,
                                               double b1,
                                               double a2,
                                               double b2,
                                               double a3,
                                               double b3)
        Compute the linear combination \(a_1 b_1 + a_2 b_2 + a_3 b_3 \) with high accuracy.
        Parameters:
        a1 - first factor of the first term
        b1 - second factor of the first term
        a2 - first factor of the second term
        b2 - second factor of the seconf term
        a3 - first factor of the third term
        b3 - second factor of the third term
        Returns:
        linear combination.
        See Also:
        Sum