qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
sqrder.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 Updates a QR factorization after deleting a row.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine sqrder(m,n,Q,ldq,R,ldr,j,w)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, ldq, ldr, j
29!> ..
30!> .. Array Arguments ..
31!> real Q(ldq,*)
32!> real R(ldr,*)
33!> real w(*)
34!> ..
35!> \endverbatim
36!>
37!> \par Purpose:
38! =============
39!> \verbatim
40!>
41!> SQRDER updates a QR factorization after deleting a row. i.e., given
42!> an m-by-m orthogonal matrix Q, an m-by-n upper trapezoidal matrix R
43!> and index j in the range 1:m, SQRDER updates Q ->Q1 and an R
44!> -> R1 so that Q1 is again orthogonal, R1 upper trapezoidal, and Q1*R1
45!> = [A(1:j-1,:); A(j+1:m,:)], where A = Q*R. (real version)
46!> \endverbatim
47!>
48!> \param[in] m
49!> \verbatim
50!> m is INTEGER
51!> The number of rows of the matrix Q. m >= 1.
52!> \endverbatim
53!>
54!> \param[in] n
55!> \verbatim
56!> n is INTEGER
57!> The number of columns of the matrix R. n >= 0.
58!> \endverbatim
59!>
60!> \param[in,out] Q
61!> \verbatim
62!> Q is REAL array, dimension (ldq,*)
63!> On entry, the orthogonal matrix Q. On exit, the
64!> updated matrix Q1.
65!> \endverbatim
66!>
67!> \param[in] ldq
68!> \verbatim
69!> ldq is INTEGER
70!> The leading dimension of Q. ldq >= m.
71!> \endverbatim
72!>
73!> \param[in,out] R
74!> \verbatim
75!> R is REAL array, dimension (ldr,*)
76!> On entry, the original matrix R. On exit, the
77!> updated matrix R1.
78!> \endverbatim
79!>
80!> \param[in] ldr
81!> \verbatim
82!> ldr is INTEGER
83!> The leading dimension of R. ldr >= m.
84!> \endverbatim
85!>
86!> \param[in] j
87!> \verbatim
88!> j is INTEGER
89!> The position of the deleted row. 1 <= j <= m.
90!> \endverbatim
91!>
92!> \param[out] w
93!> \verbatim
94!> w is REAL array, dimension (*)
95!> A workspace vector of size 2*m.
96!> \endverbatim
97!>
98!> \ingroup qrdecomp
99subroutine sqrder(m,n,Q,ldq,R,ldr,j,w)
100 use iso_fortran_env
102 integer, intent(in) :: m, n, j, ldq, ldr
103 real(real32), intent(inout) :: Q(ldq,*), R(ldr,*)
104 real(real32), intent(out) :: w(*)
105 external scopy,sqrtv1,sqrot,sqrqh
106 integer info,i,k
107 ! quick return if possible.
108 if (m == 1) return
109 ! check arguments
110 info = 0
111 if (m < 1) then
112 info = 1
113 else if (j < 1 .or. j > m) then
114 info = 7
115 end if
116 if (info /= 0) then
117 call qrupdate_xerror('SQRDER',info)
118 return
119 end if
120 ! eliminate Q(j,2:m).
121 call scopy(m,q(j,1),ldq,w,1)
122 call sqrtv1(m,w,w(m+1))
123 ! apply rotations to Q.
124 call sqrot('B',m,m,q,ldq,w(m+1),w(2))
125 ! form Q1.
126 do k = 1,m-1
127 if (j > 1) call scopy(j-1,q(1,k+1),1,q(1,k),1)
128 if (j < m) call scopy(m-j,q(j+1,k+1),1,q(j,k),1)
129 end do
130 ! apply rotations to R.
131 call sqrqh(m,n,r,ldr,w(m+1),w(2))
132 ! form R1.
133 do k = 1,n
134 do i = 1,m-1
135 r(i,k) = r(i+1,k)
136 end do
137 end do
138end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine sqrtv1(n, u, w)
Generates Givens rotations to eliminate all but the first element of a vector.
Definition sqrtv1.f90:74
subroutine sqrot(dir, m, n, q, ldq, c, s)
Applies a sequence of Givens rotations from the right to a matrix.
Definition sqrot.f90:101
subroutine sqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition sqrqh.f90:86
subroutine sqrder(m, n, q, ldq, r, ldr, j, w)
Updates a QR factorization after deleting a row.
Definition sqrder.f90:100
Module for custom error handling.