github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/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 native 6 7 import "math" 8 9 // Dlae2 computes the eigenvalues of a 2×2 symmetric matrix 10 // [a b] 11 // [b c] 12 // and returns the eigenvalue with the larger absolute value as rt1 and the 13 // smaller as rt2. 14 // 15 // Dlae2 is an internal routine. It is exported for testing purposes. 16 func (impl Implementation) Dlae2(a, b, c float64) (rt1, rt2 float64) { 17 sm := a + c 18 df := a - c 19 adf := math.Abs(df) 20 tb := b + b 21 ab := math.Abs(tb) 22 acmx := c 23 acmn := a 24 if math.Abs(a) > math.Abs(c) { 25 acmx = a 26 acmn = c 27 } 28 var rt float64 29 if adf > ab { 30 rt = adf * math.Sqrt(1+(ab/adf)*(ab/adf)) 31 } else if adf < ab { 32 rt = ab * math.Sqrt(1+(adf/ab)*(adf/ab)) 33 } else { 34 rt = ab * math.Sqrt2 35 } 36 if sm < 0 { 37 rt1 = 0.5 * (sm - rt) 38 rt2 = (acmx/rt1)*acmn - (b/rt1)*b 39 return rt1, rt2 40 } 41 if sm > 0 { 42 rt1 = 0.5 * (sm + rt) 43 rt2 = (acmx/rt1)*acmn - (b/rt1)*b 44 return rt1, rt2 45 } 46 rt1 = 0.5 * rt 47 rt2 = -0.5 * rt 48 return rt1, rt2 49 }