Пример #1
0
// Return an ordered slice of the eigenvalues of sym, and a slice of the
// eigenvectors in the same order.
func (sym *SymmetricMatrix) Eigensystem() ([]float64, [][]float64) {
	originalSize := sym.length
	reduced, convert := sym.RemoveEmptyRows()
	size := C.size_t(reduced.length)
	eigenvalues := C.gsl_vector_alloc(size)
	eigenvectors := C.gsl_matrix_alloc(size, size)
	matrix := reduced.toMatrix()
	work := C.gsl_eigen_symmv_alloc(size)
	err := C.gsl_eigen_symmv(matrix, eigenvalues, eigenvectors, work)
	if err != 0 {
		// handle it
	}
	goEigenvalues := vectorToSlice(eigenvalues)
	goEigenvectors := matrixColumnsToSlices(eigenvectors)
	C.gsl_vector_free(eigenvalues)
	C.gsl_matrix_free(eigenvectors)
	C.gsl_matrix_free(matrix)
	C.gsl_eigen_symmv_free(work)
	retEigenvectors := InsertEmptyRows(goEigenvectors, convert, originalSize)
	return goEigenvalues, retEigenvectors
}
Пример #2
0
func Symmv(a *matrix.GslMatrix, eval *vector.GslVector, evec *matrix.GslMatrix, w *GslEigenSymmvWorkspace) int32 {
	return int32(C.gsl_eigen_symmv((*C.gsl_matrix)(unsafe.Pointer(a.Ptr())), (*C.gsl_vector)(unsafe.Pointer(eval.Ptr())), (*C.gsl_matrix)(unsafe.Pointer(evec.Ptr())), (*C.gsl_eigen_symmv_workspace)(unsafe.Pointer(w.Ptr()))))
}