qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
dqhqr.f90
Go to the documentation of this file.
1! Copyright (C) 2008, 2009 VZLU Prague, a.s., Czech Republic, Jaroslav Hajek <highegg@gmail.com>
2! Copyright (C) 2026 Martin Köhler <koehlerm(AT)mpi-magdeburg.mpg.de>
3!
4! This file is part of qrupdate-ng.
5!
6! qrupdate is free software; you can redistribute it and/or modify
7! it under the terms of the GNU General Public License as published by
8! the Free Software Foundation; either version 3 of the License, or
9! (at your option) any later version.
10!
11! This program is distributed in the hope that it will be useful,
12! but WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14! GNU General Public License for more details.
15!
16! You should have received a copy of the GNU General Public License
17! along with this software; see the file COPYING. If not, see
18! <http://www.gnu.org/licenses/>.
19!
20!> \brief Reduces an upper Hessenberg matrix to upper trapezoidal form.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine dqhqr(m,n,R,ldr,c,s)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, ldr
29!> ..
30!> .. Array Arguments ..
31!> double precision R(ldr,*), c(*), s(*)
32!> ..
33!> \endverbatim
34!>
35!> \par Purpose:
36! =============
37!> \verbatim
38!>
39!> DQHQR reduces an m-by-n upper Hessenberg matrix R to upper
40!> trapezoidal form. Given an m-by-n upper Hessenberg matrix R,
41!> DQHQR applies min(m-1,n) Givens rotations from the
42!> left to eliminate the subdiagonal elements, producing an upper
43!> trapezoidal matrix.
44!>
45!> On exit, c contains the cosine parts and s contains the sine
46!> parts of the Givens rotations used in the reduction.
47!> \endverbatim
48!>
49!> \param[in] m
50!> \verbatim
51!> m is INTEGER
52!> The number of rows of the matrix R. m >= 0.
53!> \endverbatim
54!>
55!> \param[in] n
56!> \verbatim
57!> n is INTEGER
58!> The number of columns of the matrix R. n >= 0.
59!> \endverbatim
60!>
61!> \param[in,out] R
62!> \verbatim
63!> R is DOUBLE PRECISION array, dimension (ldr,n)
64!> On entry, the upper Hessenberg matrix R. On exit, the
65!> updated upper trapezoidal matrix.
66!> \endverbatim
67!>
68!> \param[in] ldr
69!> \verbatim
70!> ldr is INTEGER
71!> The leading dimension of the array R. ldr >= m.
72!> \endverbatim
73!>
74!> \param[out] c
75!> \verbatim
76!> c is DOUBLE PRECISION array, dimension (min(m-1,n))
77!> On exit, the cosine parts of the Givens rotations used
78!> to reduce R to upper trapezoidal form.
79!> \endverbatim
80!>
81!> \param[out] s
82!> \verbatim
83!> s is DOUBLE PRECISION array, dimension (min(m-1,n))
84!> On exit, the sine parts of the Givens rotations used
85!> to reduce R to upper trapezoidal form.
86!> \endverbatim
87!>
88!> \ingroup qrdecomp
89subroutine dqhqr(m,n,R,ldr,c,s)
90 use iso_fortran_env
92 integer, intent(in) :: m, n, ldr
93 real(real64), intent(inout) :: R(ldr,*)
94 real(real64), intent(out) :: c(*)
95 real(real64), intent(out) :: s(*)
96 external dlartg
97 real(real64) t
98 integer info,i,ii,j
99 ! quick return if possible.
100 if (m == 0 .or. m == 1 .or. n == 0) return
101 ! check arguments.
102 info = 0
103 if (m < 0) then
104 info = 1
105 else if (n < 0) then
106 info = 2
107 else if (ldr < m) then
108 info = 4
109 end if
110 if (info /= 0) then
111 call qrupdate_xerror('DQHQR',info)
112 return
113 end if
114 do i = 1,n
115 ! apply stored rotations, column-wise
116 t = r(1,i)
117 ii = min(m,i)
118 do j = 1,ii-1
119 r(j,i) = c(j)*t + s(j)*r(j+1,i)
120 t = c(j)*r(j+1,i) - s(j)*t
121 end do
122 if (ii < m) then
123 ! generate next rotation
124 call dlartg(t,r(ii+1,i),c(i),s(i),r(ii,i))
125 r(ii+1,i) = 0d0
126 else
127 r(ii,i) = t
128 end if
129 end do
130end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine dqhqr(m, n, r, ldr, c, s)
Reduces an upper Hessenberg matrix to upper trapezoidal form.
Definition dqhqr.f90:90
Module for custom error handling.