Class LinearAlgebra

java.lang.Object
org.esa.snap.core.util.math.LinearAlgebra

public class LinearAlgebra extends Object
Linear algebra - calculations and utilities for vectors and matrixes.

Note that for the purpose of performance the calculation functions do no argument checking.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    innerProduct(double[][] a, double[][] b, int i, int j)
    Calculates the inner product of a row in a matrix and a column in another matrix.
    static double
    innerProduct(double[] a, double[] b)
    Returns the inner product of two vectors.
    static double
    innerProduct(double[] a, double[][] b, int j)
    Calculates the inner product of a vector and a column in a matrix.
    static boolean
    isMatrix(double[][] array)
    Tests if a given double[][] array is a matrix.
    static boolean
    isMatrix(int rowCount, int colCount, double[][] array)
    Tests if a given double[][] array is a matrix with a prescribed number of rows and columns.
    static double[]
    multiply(double[][] a, double[] b)
    Multiplies a matrix by a vector (from the right).
    static double[][]
    multiply(double[][] a, double[][] b)
    Multiplies two matrixes.
    static double[][]
    multiply(double[][] a, double[][] b, double[][] c)
    Multiplies two matrixes.
    static double[]
    multiply(double[][] a, double[] b, double[] c)
    Multiplies a matrix by a vector (from the right).
    static double[]
    multiply(double[] b, double c)
    Multiplies a vector by a scalar.
    static double[]
    multiply(double[] b, double[][] a)
    Multiplies a matrix by a vector (from the left).
    static double[]
    multiply(double[] b, double[][] a, double[] c)
    Multiplies a matrix by a vector (from the left).
    static double[]
    multiplyAndSubtract(double[] b, double[][] a, double s)
    Multiplies a matrix by a vector (from the left) and subtracts a scalar.
    static double[]
    multiplyAndSubtract(double[] b, double[][] a, double s, double[] c)
    Multiplies a matrix by a vector (from the left) and subtracts a scalar.
    static double[][]
    outerProduct(double[] a, double[] b)
    Returns the outer product of two vectors.
    static double[][]
    outerProduct(double[] a, double[] b, double[][] c)
    Returns the outer product of two vectors.
    static double[][]
    subtract(double[][] a, double[] b, double[] c)
    Subtracts the outer product of two vectors from a matrix.

    Methods inherited from class java.lang.Object

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

    • LinearAlgebra

      public LinearAlgebra()
  • Method Details

    • isMatrix

      public static boolean isMatrix(double[][] array)
      Tests if a given double[][] array is a matrix.
      Parameters:
      array - the array.
      Returns:
      true if the given array is a matrix, false otherwise.
    • isMatrix

      public static boolean isMatrix(int rowCount, int colCount, double[][] array)
      Tests if a given double[][] array is a matrix with a prescribed number of rows and columns.
      Parameters:
      rowCount - the prescribed number of rows. If zero or negative, any number of rows is accepted.
      colCount - the prescribed number of columns. If zero or negative, any number of columns is accepted.
      array - the array.
      Returns:
      true if the given array is a matrix, false otherwise.
    • multiply

      public static double[] multiply(double[] b, double c)
      Multiplies a vector by a scalar.
      Parameters:
      b - the vector to be multiplied. On return contains the result.
      c - the scalar.
      Returns:
      the result vector.
    • multiply

      public static double[] multiply(double[][] a, double[] b)
      Multiplies a matrix by a vector (from the right).
      Parameters:
      a - the matrix.
      b - the vector.
      Returns:
      the result vector.
    • multiply

      public static double[] multiply(double[][] a, double[] b, double[] c)
      Multiplies a matrix by a vector (from the right).
      Parameters:
      a - the matrix.
      b - the vector.
      c - the result vector.
      Returns:
      the result vector.
    • multiply

      public static double[] multiply(double[] b, double[][] a)
      Multiplies a matrix by a vector (from the left).
      Parameters:
      b - the vector.
      a - the matrix.
      Returns:
      the result vector.
    • multiply

      public static double[] multiply(double[] b, double[][] a, double[] c)
      Multiplies a matrix by a vector (from the left).
      Parameters:
      b - the vector.
      a - the matrix.
      c - the result vector.
      Returns:
      the result vector.
    • multiplyAndSubtract

      public static double[] multiplyAndSubtract(double[] b, double[][] a, double s)
      Multiplies a matrix by a vector (from the left) and subtracts a scalar.
      Parameters:
      b - the vector.
      a - the matrix.
      s - the scalar.
      Returns:
      the result vector.
    • multiplyAndSubtract

      public static double[] multiplyAndSubtract(double[] b, double[][] a, double s, double[] c)
      Multiplies a matrix by a vector (from the left) and subtracts a scalar.
      Parameters:
      b - the vector.
      a - the matrix.
      s - the scalar.
      c - the result vector.
      Returns:
      the result vector.
    • innerProduct

      public static double innerProduct(double[] a, double[] b)
      Returns the inner product of two vectors.
      Parameters:
      a - the first vector.
      b - the second vector.
      Returns:
      the inner product.
    • innerProduct

      public static double innerProduct(double[] a, double[][] b, int j)
      Calculates the inner product of a vector and a column in a matrix.
      Parameters:
      a - the vector.
      b - the matrix.
      j - the index of a column in b.
      Returns:
      the inner product of a and the ith column in b.
    • innerProduct

      public static double innerProduct(double[][] a, double[][] b, int i, int j)
      Calculates the inner product of a row in a matrix and a column in another matrix.
      Parameters:
      a - the first matrix.
      b - the second matrix.
      i - the index of a row in a.
      j - the index of a column in b.
      Returns:
      the inner product of the ith row in a and the jth column in b.
    • outerProduct

      public static double[][] outerProduct(double[] a, double[] b)
      Returns the outer product of two vectors.
      Parameters:
      a - the first vector.
      b - the second vector.
      Returns:
      the outer product.
    • outerProduct

      public static double[][] outerProduct(double[] a, double[] b, double[][] c)
      Returns the outer product of two vectors.
      Parameters:
      a - the first vector.
      b - the second vector.
      c - the result vector.
      Returns:
      the result vector.
    • multiply

      public static double[][] multiply(double[][] a, double[][] b)
      Multiplies two matrixes.
      Parameters:
      a - the first matrix.
      b - the second matrix.
      Returns:
      the result matrix.
    • multiply

      public static double[][] multiply(double[][] a, double[][] b, double[][] c)
      Multiplies two matrixes.
      Parameters:
      a - the first matrix.
      b - the second matrix.
      c - the result matrix.
      Returns:
      the result matrix.
    • subtract

      public static double[][] subtract(double[][] a, double[] b, double[] c)
      Subtracts the outer product of two vectors from a matrix.
      Parameters:
      a - the matrix. On return contains the result matrix.
      b - the first vector.
      c - the second vector.
      Returns:
      the result matrix.