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

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

Introduction

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

Prototype

double getTrace() throws NonSquareMatrixException;

Source Link

Document

Returns the <a href="http://mathworld.wolfram.com/MatrixTrace.html"> trace</a> of the matrix (the sum of the elements on the main diagonal).

Usage

From source file:com.opengamma.analytics.math.matrix.CommonsMatrixAlgebra.java

/**
 * {@inheritDoc}//  w  ww  .j  a  v  a 2 s .c  o m
 */
@Override
public double getTrace(final Matrix<?> m) {
    Validate.notNull(m, "m");
    if (m instanceof DoubleMatrix2D) {
        final RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix2D) m);
        return temp.getTrace();
    }
    throw new IllegalArgumentException("Can only find trace of DoubleMatrix2D; have " + m.getClass());
}