<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lae2.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_LAE2_HH
11#define TLAPACK_LAE2_HH
12
14
15namespace tlapack {
16
48template <TLAPACK_SCALAR T>
49void lae2(T a, T b, T c, T& s1, T& s2)
50{
51 // Constants
52 const T zero(0);
53 const T one(1);
54 const T two(2);
55 const T half(0.5);
56
57 // Compute the eigenvalues
58 T sm = a + c;
59 T df = a - c;
60 T adf = abs(df);
61 T tb = b + b;
62 T ab = abs(tb);
63 T acmx, acmn;
64 if (abs(a) > abs(c)) {
65 acmx = a;
66 acmn = c;
67 }
68 else {
69 acmx = c;
70 acmn = a;
71 }
72
73 T rt;
74 if (adf > ab) {
75 rt = adf * sqrt(one + square(ab / adf));
76 }
77 else if (adf < ab) {
78 rt = ab * sqrt(one + square(adf / ab));
79 }
80 else {
81 // This case includes case AB=ADF=0
82 rt = ab * sqrt(two);
83 }
84
85 if (sm < zero) {
86 s1 = half * (sm - rt);
87 // Order of execution important.
88 // To get fully accurate smaller eigenvalue,
89 // next line needs to be executed in higher precision.
90 s2 = (acmx / s1) * acmn - (b / s1) * b;
91 }
92 else if (sm > zero) {
93 s1 = half * (sm + rt);
94 // Order of execution important.
95 // To get fully accurate smaller eigenvalue,
96 // next line needs to be executed in higher precision.
97 s2 = (acmx / s1) * acmn - (b / s1) * b;
98 }
99 else {
100 // Includes case s1 = s2 = 0
101 s1 = half * rt;
102 s2 = -half * rt;
103 }
104}
105} // namespace tlapack
106
107#endif // TLAPACK_LAE2_HH
void lae2(T a, T b, T c, T &s1, T &s2)
Computes the eigenvalues of a real symmetric 2x2 matrix A [ a b ] [ b c ].
Definition lae2.hpp:49
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113