// Simple Eigenvalue calculation using LAPACK/CGO functions
// Built with:
// CGO_LDFLAGS="-L/opt/Downloads/OpenBLAS -lopenblas" go build cgeev.go
package main
import (
"fmt"
)
func main() {
jobvl := lapack.Job('V')
jobvr := lapack.Job('V')
n, lda, ldvl, lvdr, lwork := 2, 2, 2, 2, 4
a := []complex128{1 + 1i, 2 - 1i, 2 + 1i, 1 - 1i}
showMatrix("Working matrix:", a)
w := make([]complex128, 2)
vl := make([]complex128, 4)
vr := make([]complex128, 4)
work := make([]complex128, 4)
rwork := make([]float64, 4)
lapacke.Zgeev(jobvl, jobvr, n, a, lda, w, vl, ldvl, vr, lvdr,
work, lwork, rwork)
showMatrix("Left Eigenvectors:", vl)
showMatrix("Right Eigenvectors:", vr)
showMatrix("Eigenvalues:", w)
}
func showMatrix(label string, m []complex128) {
fmt.Printf("\n%s:\n", label)
for i := range m {
fmt.Printf("%4.2f\t", m[i])
if i%2 != 0 {
fmt.Printf("\n")
}
}
}
---------------------------------------
go build zgeev.go (runs without any errors and produces zgeev executable)
./zgeev
Working matrix::
(1.00+1.00i) (2.00-1.00i)
(2.00+1.00i) (1.00-1.00i)
Left Eigenvectors::
(0.71+0.00i) (0.71+0.00i)
(0.42+0.57i) (-0.71-0.00i)
Right Eigenvectors::
(0.71-0.00i) (0.71+0.00i)
(0.71+0.00i) (-0.42-0.57i)
Eigenvalues::
(3.00-0.00i) (-1.00+0.00i)
Thanks for the help!
Dave