Example usage for org.apache.commons.math.linear BigMatrix getEntry

List of usage examples for org.apache.commons.math.linear BigMatrix getEntry

Introduction

In this page you can find the example usage for org.apache.commons.math.linear BigMatrix getEntry.

Prototype

BigDecimal getEntry(int row, int column) throws MatrixIndexException;

Source Link

Document

Returns the entry in the specified row and column.

Usage

From source file:rmc.mat.RmcNewtonSolver.java

public void iterateUntilMSVlessThan(double maxMSV, long maxIterations) throws Exception {
    while (currentMSV > maxMSV && currentIterations < maxIterations) {
        System.out.println(currentMSV);
        currentMSV = 0;//from w  ww  .  j  av  a  2  s  .c  o  m
        currentIterations++;
        BigDecimal jacobianMatrix[][] = new BigDecimal[inputVariables.size()][inputVariables.size()];
        for (int row = 0; row < inputVariables.size(); row++) {
            for (int col = 0; col < inputVariables.size(); col++) {
                jacobianMatrix[row][col] = jacobianEquationMatrix[row][col].calculate();
            }
        }
        BigMatrix invertedJacobianMatrix = new BigMatrixImpl(jacobianMatrix).inverse();
        for (int row = 0; row < inputVariables.size(); row++) {
            BigDecimal diffValue = new BigDecimal(0);
            for (int col = 0; col < inputVariables.size(); col++) {
                BigDecimal functionToOptimizeValue = functionToOptimize[col].calculate();
                diffValue = diffValue
                        .add(invertedJacobianMatrix.getEntry(row, col).multiply(functionToOptimizeValue));
            }
            resultVariables.set(row,
                    inputVariables.getVariableValueFromId(row).subtract(diffValue).stripTrailingZeros());
        }
        for (RmcEquation rmcEquation : rmcEquations) {
            currentMSV = Math.max(currentMSV,
                    resultVariables.get(rmcEquation.variableId)
                            .subtract(inputVariables.getVariableValueFromId(rmcEquation.variableId)).abs()
                            .doubleValue());
            inputVariables.setVariableValue(rmcEquation.variableName,
                    resultVariables.get(rmcEquation.variableId));
        }
    }
}