Example usage for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector

List of usage examples for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector.

Prototype

public ArrayRealVector(double[] v1, double[] v2) 

Source Link

Document

Construct a vector by appending one vector to another vector.

Usage

From source file:org.lambda3.indra.util.VectorIterator.java

public RealVector readDenseVector(int dimensions) throws IOException {
    double[] vector = new double[dimensions];

    for (int i = 0; i < dimensions; i++) {
        vector[i] = (double) input.readFloat();
    }//from w w w.  j a  v a 2s  .  com

    return new ArrayRealVector(vector, false);
}

From source file:org.meteoinfo.math.linalg.LinalgUtil.java

/**
 * Solve a linear matrix equation, or system of linear scalar equations.
 * @param a Coefficient matrix.//w  w  w .  j  a  va 2  s .  c  o m
 * @param b Ordinate or dependent variable? values.
 * @return Solution to the system a x = b. Returned shape is identical to b.
 */
public static Array solve(Array a, Array b) {
    Array r = Array.factory(DataType.DOUBLE, b.getShape());
    double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
    RealMatrix coefficients = new Array2DRowRealMatrix(aa, false);
    DecompositionSolver solver = new LUDecomposition(coefficients).getSolver();
    double[] bb = (double[]) ArrayUtil.copyToNDJavaArray(b);
    RealVector constants = new ArrayRealVector(bb, false);
    RealVector solution = solver.solve(constants);
    for (int i = 0; i < r.getSize(); i++) {
        r.setDouble(i, solution.getEntry(i));
    }

    return r;
}