예제 #1
0
파일: eigen_test.go 프로젝트: postfix/gsl-1
func TestEigenNonsymm(t *testing.T) {
	data := []float64{-1.0, 1.0, -1.0, 1.0,
		-8.0, 4.0, -2.0, 1.0,
		27.0, 9.0, 3.0, 1.0,
		64.0, 16.0, 4.0, 1.0}

	m := matrix.ViewArray(data, 4, 4)
	eval := vector.VectorComplexAlloc(4)
	evec := matrix.MatrixComplexAlloc(4, 4)

	w := eigen.NonsymmvAlloc(4)
	eigen.Nonsymmv(m.Matrix(), eval, evec, w)
	eigen.NonsymmvSort(eval, evec, eigen.EIGEN_SORT_ABS_DESC)

	for i := 0; i < 4; i++ {
		evalI := vector.ComplexGet(eval, i)
		evecI := matrix.ComplexColumn(evec, i)
		fmt.Printf("eigenvalue = %g + %gi\n",
			real(evalI), imag(evalI))
		fmt.Printf("eigenvector = \n")
		for j := 0; j < 4; j++ {
			z := vector.ComplexGet(evecI.Vector(), j)
			fmt.Printf("%g + %gi\n", real(z), imag(z))
		}
	}
}
예제 #2
0
파일: blas_test.go 프로젝트: postfix/gsl-1
func TestBlas(t *testing.T) {
	a := []float64{0.11, 0.12, 0.13,
		0.21, 0.22, 0.23}
	b := []float64{1011, 1012,
		1021, 1022,
		1031, 1032}
	c := []float64{0.00, 0.00,
		0.00, 0.00}

	va := matrix.ViewArray(a, 2, 3)
	vb := matrix.ViewArray(b, 3, 2)
	vc := matrix.ViewArray(c, 2, 2)

	blas.Dgemm(blas.NoTrans, blas.NoTrans, 1.0, va.Matrix(), vb.Matrix(), 0.0, vc.Matrix())
	fmt.Printf("[ %g, %g\n", c[0], c[1])
	fmt.Printf("  %g, %g ]\n", c[2], c[3])
}
예제 #3
0
파일: ode_test.go 프로젝트: dtromb/gogsl
func Df(t float64, y []float64, dfdy []float64, dfdt []float64, params interface{}) int {
	mu := *params.(*float64)
	dfdyMat := matrix.ViewArray(dfdy, 2, 2)
	m := dfdyMat.Matrix()
	matrix.Set(m, 0, 0, 0.0)
	matrix.Set(m, 0, 1, 1.0)
	matrix.Set(m, 1, 0, -2.0*mu*y[0]*y[1]-1.0)
	matrix.Set(m, 1, 1, -mu*(y[0]*y[0]-1.0))
	dfdt[0] = 0.0
	dfdt[1] = 0.0
	return int(gogsl.GSL_SUCCESS)
}
예제 #4
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")
}
예제 #5
0
파일: eigen_test.go 프로젝트: postfix/gsl-1
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")
	}
}