gonum.org/v1/gonum@v0.14.0/lapack/gonum/dlas2.go (about) 1 // Copyright ©2015 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 gonum 6 7 import "math" 8 9 // Dlas2 computes the singular values of the 2×2 matrix defined by 10 // 11 // [F G] 12 // [0 H] 13 // 14 // The smaller and larger singular values are returned in that order. 15 // 16 // Dlas2 is an internal routine. It is exported for testing purposes. 17 func (impl Implementation) Dlas2(f, g, h float64) (ssmin, ssmax float64) { 18 fa := math.Abs(f) 19 ga := math.Abs(g) 20 ha := math.Abs(h) 21 fhmin := math.Min(fa, ha) 22 fhmax := math.Max(fa, ha) 23 if fhmin == 0 { 24 if fhmax == 0 { 25 return 0, ga 26 } 27 v := math.Min(fhmax, ga) / math.Max(fhmax, ga) 28 return 0, math.Max(fhmax, ga) * math.Sqrt(1+v*v) 29 } 30 if ga < fhmax { 31 as := 1 + fhmin/fhmax 32 at := (fhmax - fhmin) / fhmax 33 au := (ga / fhmax) * (ga / fhmax) 34 c := 2 / (math.Sqrt(as*as+au) + math.Sqrt(at*at+au)) 35 return fhmin * c, fhmax / c 36 } 37 au := fhmax / ga 38 if au == 0 { 39 return fhmin * fhmax / ga, ga 40 } 41 as := 1 + fhmin/fhmax 42 at := (fhmax - fhmin) / fhmax 43 c := 1 / (math.Sqrt(1+(as*au)*(as*au)) + math.Sqrt(1+(at*au)*(at*au))) 44 return 2 * (fhmin * c) * au, ga / (c + c) 45 }