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

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

Introduction

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

Prototype

RealMatrix getColumnMatrix(int column) throws MatrixIndexException;

Source Link

Document

Returns 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;
    double k = 0;
    double prevK = 0;
    int num = 0;/*  www.j  a v  a2s.  c o m*/
    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;
}