github.com/gopherd/gonum@v0.0.4/lapack/testlapack/dlae2.go (about) 1 // Copyright ©2016 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testlapack 6 7 import ( 8 "fmt" 9 "math" 10 "testing" 11 ) 12 13 type Dlae2er interface { 14 Dlae2(a, b, c float64) (rt1, rt2 float64) 15 } 16 17 func Dlae2Test(t *testing.T, impl Dlae2er) { 18 for _, test := range []struct { 19 a, b, c float64 20 }{ 21 {-10, 5, 3}, 22 {3, 5, -10}, 23 {0, 3, 0}, 24 {1, 3, 1}, 25 {1, -3, 1}, 26 {5, 0, 3}, 27 {3, 0, -5}, 28 {1, 3, 1.02}, 29 {1.02, 3, 1}, 30 {1, -3, -9}, 31 } { 32 a := test.a 33 b := test.b 34 c := test.c 35 rt1, rt2 := impl.Dlae2(a, b, c) 36 37 errStr := fmt.Sprintf("a = %v, b = %v, c = %v", a, b, c) 38 // Check if rt1 and rt2 are eigenvalues by checking if det(a - λI) = 0 39 a1 := a - rt1 40 c1 := c - rt1 41 det := a1*c1 - b*b 42 if math.Abs(det) > 1e-10 { 43 t.Errorf("First eigenvalue mismatch. %s. Det = %v", errStr, det) 44 } 45 46 a2 := a - rt2 47 c2 := c - rt2 48 det = a2*c2 - b*b 49 if math.Abs(det) > 1e-10 { 50 t.Errorf("Second eigenvalue mismatch. %s. Det = %v", errStr, det) 51 } 52 } 53 }