Example usage for org.apache.commons.math3.linear RealMatrix addToEntry

List of usage examples for org.apache.commons.math3.linear RealMatrix addToEntry

Introduction

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

Prototype

void addToEntry(int row, int column, double increment) throws OutOfRangeException;

Source Link

Document

Adds (in place) the specified value to the specified entry of this matrix.

Usage

From source file:resolution.VolumesFinis.java

public double[] solveCommonMaths(IFonction fonction, double u0, double u1, double[] mesh) {
    double[] result = null;
    int n = mesh.length;

    if (n == 0) {
        return result;
    }//w ww . ja v a 2 s.c  o  m

    // Calcul des h(i) et h(i+1/2)
    double[] hi2 = new double[n + 1];
    double[] hi = new double[n];

    hi2[0] = mesh[0];
    for (int i = 1; i < n; i++) {
        hi2[i] = mesh[i] - mesh[i - 1];
        hi[i - 1] = 0.5 * (hi2[i] + hi2[i - 1]);
    }
    hi2[n] = 1 - mesh[n - 1];
    hi[n - 1] = 0.5 * (hi2[n] + hi2[n - 1]);

    // Construction de la matrice A     
    double temp = 1.0 / hi2[0] + 1.0 / hi2[1];

    // Cration de la matrice A
    RealMatrix matrice = new Array2DRowRealMatrix(n, n);
    matrice.addToEntry(0, 0, temp);

    if (n > 1) {
        //matrice.addToEntry(0, 1, -1.0/hi2[0]);
        for (int i = 1; i < n; i++) {
            matrice.addToEntry(i, i, (1.0 / hi2[i] + 1.0 / hi2[i + 1]));
            matrice.addToEntry(i, i - 1, -1.0 / hi2[i]);
            matrice.addToEntry(i - 1, i, -1.0 / hi2[i + 1]);
        }
    }

    DecompositionSolver solver = new LUDecomposition(matrice).getSolver();

    //Construction du vecteur b
    double b[];
    try {
        b = fonction.evaluer(mesh);

        for (int i = 0; i < n; i++) {
            b[i] = b[i] * hi[i];
        }
    } catch (Exception e) {
        return null;
    }

    b[0] = b[0] + u0 / hi2[0];
    b[n - 1] = b[n - 1] + u1 / hi2[n - 1];

    /*
    RealVector bVect = new ArrayRealVector(n);
    for (int i=0; i<n; i++)
    bVect.setEntry(i, b[i]);
    //*/
    ArrayRealVector bVect = new ArrayRealVector(b);
    //Matrix bMatrix = new Matrix(b, n);

    //Rsolution de l'quation

    //RealVector res = solver.solve(bVect);
    // double[] res1 = res.toArray();

    return solver.solve(bVect).toArray();
}

From source file:scorePairing.ScorePairingWithStaticMethods.java

public static void translateBarycenterListOfPointToOrigin(RealMatrix matrix, RealVector barycenter) {

    int countOfPoint = matrix.getColumnDimension();

    for (int i = 0; i < countOfPoint; i++) {
        matrix.addToEntry(0, i, -1.0 * barycenter.getEntry(0));
        matrix.addToEntry(1, i, -1.0 * barycenter.getEntry(1));
        matrix.addToEntry(2, i, -1.0 * barycenter.getEntry(2));
    }/*from  ww  w  .j  a  va 2 s  .  co m*/
}