Hi,
I'm a newcomer to Breeze, attempting to use it to calculate the characteristic polynomial of a matrix via the Souriau/von_Faddejew/Leverrier method:
http://stackoverflow.com/questions/23937481/souriau-method-for-characteristic-polynomial
Below, is the code, which doesn't currently compile. There reported issues are:
1. For C + eyedash:
could not find implicit value for parameter op: breeze.linalg.operators.OpAdd.Impl2[breeze.linalg.Matrix[Double],breeze.linalg.DenseMatrix[Double],That]
I presume this is because breeze does not know that C is square? If so, how can I provide the required information?
2. For trace(C)
could not find implicit value for parameter impl: breeze.linalg.trace.Impl[breeze.linalg.Matrix[Double],VR
Is there something else I need to import?
/////////////////////////////////////////////////////////////////////////////////
import breeze.linalg._
import breeze.numerics._
import breeze.math._
// ...
def charPoly(A: Matrix[Double]): DenseVector[Double] = {
require(A.rows == A.cols)
var C = A.copy
val n = A.rows
val c = DenseVector.zeros[Double](n)
val I = DenseMatrix.eye[Double](n)
for( k <- 0 until n ) {
if( k>0 ) {
val eyedash = c(n-k) :* I
val cplus = C + eyedash
C = A * cplus
}
val x = -trace(C)/k
c(n−k) = x
}
c
}
Thanks,
Jerry.