Exemple #1
0
func TestLinalg(t *testing.T) {

	aData := []float64{0.18, 0.60, 0.57, 0.96,
		0.41, 0.24, 0.99, 0.58,
		0.14, 0.30, 0.97, 0.66,
		0.51, 0.13, 0.19, 0.85}
	bData := []float64{1.0, 2.0, 3.0, 4.0}
	m := matrix.ViewArray(aData, 4, 4)
	b := vector.ViewArray(bData, 4)
	x := vector.VectorAlloc(4)
	p := permutation.PermutationAlloc(4)
	linalg.LUDecomp(m.Matrix(), p)
	linalg.LUSolve(m.Matrix(), p, b.Vector(), x)
	fmt.Printf("x = \n")
	vector.Fprintf(os.Stdout, x, "%g")
}
Exemple #2
0
func TestEigen(t *testing.T) {

	data := []float64{1.0, 1 / 2.0, 1 / 3.0, 1 / 4.0,
		1 / 2.0, 1 / 3.0, 1 / 4.0, 1 / 5.0,
		1 / 3.0, 1 / 4.0, 1 / 5.0, 1 / 6.0,
		1 / 4.0, 1 / 5.0, 1 / 6.0, 1 / 7.0}
	m := matrix.ViewArray(data, 4, 4)
	eval := vector.VectorAlloc(4)
	evec := matrix.MatrixAlloc(4, 4)
	w := eigen.SymmvAlloc(4)
	eigen.Symmv(m.Matrix(), eval, evec, w)
	eigen.SymmvSort(eval, evec, eigen.EIGEN_SORT_ABS_ASC)
	for i := 0; i < 4; i++ {
		evalI := vector.Get(eval, i)
		evecI := matrix.Column(evec, i)
		fmt.Printf("eigenvalue = %g\n", evalI)
		fmt.Printf("eigenvector = \n")
		vector.Fprintf(os.Stdout, evecI.Vector(), "%g")
	}
}