<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lahqr_eig22.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_LAHQR_EIG22_HH
11#define TLAPACK_LAHQR_EIG22_HH
12
14
15namespace tlapack {
16
33template <TLAPACK_SCALAR T>
36{
37 // Using
38 using real_t = real_type<T>;
39
40 // Constants
41 const real_t zero(0);
42 const real_t two(2);
43
44 const T s = abs1(a00) + abs1(a01) + abs1(a10) + abs1(a11);
45 if (s == zero) {
46 s1 = zero;
47 s2 = zero;
48 return;
49 }
50
51 a00 = a00 / s;
52 a01 = a01 / s;
53 a10 = a10 / s;
54 a11 = a11 / s;
55 const T tr = (a00 + a11) / two;
56 const complex_type<T> det = (a00 - tr) * (a00 - tr) + a01 * a10;
57 const complex_type<T> rtdisc = sqrt(det);
58
59 s1 = s * (tr + rtdisc);
60 s2 = s * (tr - rtdisc);
61}
62
63} // namespace tlapack
64
65#endif // TLAPACK_LAHQR_EIG22_HH
constexpr real_type< T > abs1(const T &x)
1-norm absolute value, |Re(x)| + |Im(x)|
Definition utils.hpp:133
void lahqr_eig22(T a00, T a01, T a10, T a11, complex_type< T > &s1, complex_type< T > &s2)
Computes the eigenvalues of a 2x2 matrix A.
Definition lahqr_eig22.hpp:34
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