Mercurial > octave-nkf
annotate libcruft/qrupdate/dqrder.f @ 7553:56be6f31dd4e
implementation of QR factorization updating
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 04 Mar 2008 21:47:11 -0500 |
parents | |
children |
rev | line source |
---|---|
7553
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 c Copyright (C) 2008 VZLU Prague, a.s., Czech Republic |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 c Author: Jaroslav Hajek <highegg@gmail.com> |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 c This source is free software; you can redistribute it and/or modify |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 c it under the terms of the GNU General Public License as published by |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 c the Free Software Foundation; either version 2 of the License, or |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 c (at your option) any later version. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 c This program is distributed in the hope that it will be useful, |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 c but WITHOUT ANY WARRANTY; without even the implied warranty of |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 c GNU General Public License for more details. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 c You should have received a copy of the GNU General Public License |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 c along with this software; see the file COPYING. If not, see |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 c <http://www.gnu.org/licenses/>. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 subroutine dqrder(m,n,Q,Q1,R,R1,j) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 c purpose: updates a QR factorization after deleting a row. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 c i.e., given an m-by-m orthogonal matrix Q, an m-by-n |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 c upper trapezoidal matrix R and index j in the range |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 c 1:m, this subroutine forms the (m-1)-by-(m-1) matrix |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
24 c Q1 and an (m-1)-by-n matrix R1 so that Q1 is again |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 c orthogonal, R1 upper trapezoidal, and |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 c Q1*R1 = [A(1:j-1,:); A(j+1:m,:)], where A = Q*R. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 c (real version) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 c arguments: |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 c m (in) number of rows of the matrix R. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 c n (in) number of columns of the matrix R |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 c Q (in) the orthogonal matrix Q |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 c Q1 (out) the updated matrix Q1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 c R (in) the upper trapezoidal matrix R |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 c R1 (out) the updated matrix R1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 c j (in) the position of the new row in R1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 integer m,n,j |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 double precision Q(m,m),Q1(m-1,m-1),R(m,n),R1(m-1,n) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 double precision c |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 double precision s,rr,w |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 external xerbla,dlacpy,dlartg,drot,dscal,daxpy |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 integer i |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 c quick return if possible |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 if (m == 1) return |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 c check arguments |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 info = 0 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 if (m < 1) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 info = 1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 else if (j < 1 .or. j > n) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 info = 7 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 if (info /= 0) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 call xerbla('DQRDER',info) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 c setup the new matrix Q1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 c permute the columns of Q and rows of R so that the deleted row ends |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 c up being the topmost row. |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 if (j > 1) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 call dlacpy('0',j-1,m-1,Q(1,2),m,Q1(1,1),m-1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 if (j < m) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 call dlacpy('0',m-j,m-1,Q(j+1,2),m,Q1(j,1),m-1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 c setup the new matrix R1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 call dlacpy('0',m-1,n,R(2,1),m,R1(1,1),m-1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 c eliminate Q(j,2:m) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 w = Q(j,m) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 do i = m-1,2,-1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 call dlartg(Q(j,i),w,c,s,rr) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 w = rr |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
72 c apply rotation to rows of R1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
73 if (i <= n) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
74 call drot(n-i+1,R1(i-1,i),m-1,R1(i,i),m-1,c,s) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
75 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 c apply rotation to columns of Q1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 call drot(m-1,Q1(1,i-1),1,Q1(1,i),1,c,s) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
78 end do |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
79 c the last iteration is special, as we don't have the first row of |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
80 c R and first column of Q |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
81 call dlartg(Q(j,1),w,c,s,rr) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
82 w = rr |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
83 call dscal(n,c,R1(1,1),m-1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
84 call daxpy(n,-s,R(1,1),m,R1(1,1),m-1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
85 c apply rotation to columns of Q1 |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
86 call dscal(m-1,c,Q1(1,1),1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
87 if (j > 1) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
88 call daxpy(j-1,-s,Q(1,1),1,Q1(1,1),1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
89 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
90 if (j < m) then |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
91 call daxpy(m-j,-s,Q(j+1,1),1,Q1(j,1),1) |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
92 end if |
56be6f31dd4e
implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
93 end |