Char Poly via Souriau method

25 views
Skip to first unread message

Jerry

unread,
Feb 5, 2016, 12:28:12 PM2/5/16
to Scala Breeze
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.

David Hall

unread,
Feb 5, 2016, 12:30:46 PM2/5/16
to scala-...@googlegroups.com
Hi Jerry,

Lots of stuff in Breeze still only works for DenseMatrix[Double] rather than Matrix[Double], I'm surprised about the OpAdd one, but that's what's going on. If you make A be a DenseMatrix, it should work fine.

-- David

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/b58333c1-b77e-40f3-a65c-681039aa4588%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages