Example usage for org.apache.commons.math.linear RealMatrix setColumnMatrix

List of usage examples for org.apache.commons.math.linear RealMatrix setColumnMatrix

Introduction

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

Prototype

void setColumnMatrix(int column, RealMatrix matrix) throws MatrixIndexException, InvalidMatrixException;

Source Link

Document

Sets the entries in column number column as a column matrix.

Usage

From source file:PowerMethod.power_method.java

public static power_object power_method(RealMatrix A, RealMatrix v, double epsilon, int N) {
    RealMatrix uInit = v;// w w  w.ja  v a 2  s.com
    double k = 0;
    double prevK = 0;
    int num = 0;
    double accuracy;
    for (int i = N; i > 0; i--) {
        RealMatrix uN = A.multiply(uInit);
        k = uN.getEntry(0, 0);
        for (int j = 0; j < uN.getRowDimension(); j++) {
            uN.setEntry(j, 0, uN.getEntry(j, 0) / k);
        }
        uInit = uN;

        accuracy = Math.abs(k - prevK);
        if (accuracy <= epsilon) {
            break;
        }

        if (accuracy > epsilon && i == 1) {
            return null;
        }

        prevK = k;
        num++;
    }
    double eVal = k;
    RealMatrix eVec = new Array2DRowRealMatrix(uInit.getRowDimension(), uInit.getColumnDimension());

    eVec.setColumnMatrix(0, uInit.getColumnMatrix(0));
    power_object retVal = new power_object(eVal, eVec, num);
    return retVal;
}