Search in sources :

Example 6 with SparseMatrixCell

use of maspack.matrix.SparseMatrixCell in project artisynth_core by artisynth.

the class IncompleteCholeskyDecomposition method solve.

/**
 * Solves L * x = b
 */
public boolean solve(VectorNd x, VectorNd b) throws ImproperStateException, ImproperSizeException {
    double[] xbuf = x.getBuffer();
    double[] bbuf = b.getBuffer();
    for (int i = 0; i < n; i++) {
        double v = bbuf[i];
        SparseMatrixCell ijcell = C.getRow(i);
        while (ijcell.j < i) {
            v -= xbuf[ijcell.j] * ijcell.value;
            ijcell = ijcell.next;
        }
        v /= C.get(i, i);
        xbuf[i] = v;
    }
    return true;
}
Also used : SparseMatrixCell(maspack.matrix.SparseMatrixCell)

Example 7 with SparseMatrixCell

use of maspack.matrix.SparseMatrixCell in project artisynth_core by artisynth.

the class IncompleteLUDecomposition method solveU.

// public boolean solveDense(Vector x, Vector b) throws
// ImproperStateException, ImproperSizeException
// {
// for(int i = 0; i < n; i++)
// {
// double v = b.get(i);
// 
// for(int j = 0; j < i; j++)
// {
// v -= x.get(j) * L.get(i, j);
// }
// cols
// v /= L.get(i, i);
// 
// x.set(i, v);
// }
// 
// return true;
// }
/**
 * Solves U * x = b
 */
public boolean solveU(VectorNd x, VectorNd b) throws ImproperStateException, ImproperSizeException {
    double[] xbuf = x.getBuffer();
    double[] bbuf = b.getBuffer();
    for (int i = (n - 1); i >= 0; i--) {
        double v = bbuf[i];
        SparseMatrixCell jicell = U.getRow(i);
        while (jicell != null && jicell.j <= i) jicell = jicell.next;
        while (jicell != null) {
            v -= xbuf[jicell.j] * jicell.value;
            jicell = jicell.next;
        }
        v /= U.get(i, i);
        xbuf[i] = v;
    }
    return true;
}
Also used : SparseMatrixCell(maspack.matrix.SparseMatrixCell)

Example 8 with SparseMatrixCell

use of maspack.matrix.SparseMatrixCell in project artisynth_core by artisynth.

the class IncompleteLUDecomposition method solveL.

/**
 * Solves L * x = b
 */
public boolean solveL(VectorNd x, VectorNd b) throws ImproperStateException, ImproperSizeException {
    double[] xbuf = x.getBuffer();
    double[] bbuf = b.getBuffer();
    for (int i = 0; i < n; i++) {
        double v = bbuf[i];
        SparseMatrixCell ijcell = L.getRow(i);
        while (ijcell.j < i) {
            v -= xbuf[ijcell.j] * ijcell.value;
            ijcell = ijcell.next;
        }
        // v /= L.get(i, i);
        xbuf[i] = v;
    }
    return true;
}
Also used : SparseMatrixCell(maspack.matrix.SparseMatrixCell)

Aggregations

SparseMatrixCell (maspack.matrix.SparseMatrixCell)8 SparseMatrixNd (maspack.matrix.SparseMatrixNd)4 SparseVectorCell (maspack.matrix.SparseVectorCell)1 SparseVectorNd (maspack.matrix.SparseVectorNd)1