File: dlae2.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (51 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright ©2016 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gonum

import "math"

// Dlae2 computes the eigenvalues of a 2×2 symmetric matrix
//
//	[a b]
//	[b c]
//
// and returns the eigenvalue with the larger absolute value as rt1 and the
// smaller as rt2.
//
// Dlae2 is an internal routine. It is exported for testing purposes.
func (impl Implementation) Dlae2(a, b, c float64) (rt1, rt2 float64) {
	sm := a + c
	df := a - c
	adf := math.Abs(df)
	tb := b + b
	ab := math.Abs(tb)
	acmx := c
	acmn := a
	if math.Abs(a) > math.Abs(c) {
		acmx = a
		acmn = c
	}
	var rt float64
	if adf > ab {
		rt = adf * math.Sqrt(1+(ab/adf)*(ab/adf))
	} else if adf < ab {
		rt = ab * math.Sqrt(1+(adf/ab)*(adf/ab))
	} else {
		rt = ab * math.Sqrt2
	}
	if sm < 0 {
		rt1 = 0.5 * (sm - rt)
		rt2 = (acmx/rt1)*acmn - (b/rt1)*b
		return rt1, rt2
	}
	if sm > 0 {
		rt1 = 0.5 * (sm + rt)
		rt2 = (acmx/rt1)*acmn - (b/rt1)*b
		return rt1, rt2
	}
	rt1 = 0.5 * rt
	rt2 = -0.5 * rt
	return rt1, rt2
}