Mercurial > octave-nkf
annotate libcruft/qrupdate/zch1dn.f @ 7948:af10baa63915 ss-3-1-50
3.1.50 snapshot
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Jul 2008 17:42:48 -0400 |
parents | 7c9ba697a479 |
children |
rev | line source |
---|---|
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 c Copyright (C) 2008 VZLU Prague, a.s., Czech Republic |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 c Author: Jaroslav Hajek <highegg@gmail.com> |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 c This source is free software; you can redistribute it and/or modify |
40574114c514
implement Cholesky 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 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 c the Free Software Foundation; either version 2 of the License, or |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 c (at your option) any later version. |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 c This program is distributed in the hope that it will be useful, |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 c but WITHOUT ANY WARRANTY; without even the implied warranty of |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 c GNU General Public License for more details. |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 c You should have received a copy of the GNU General Public License |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 c along with this software; see the file COPYING. If not, see |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 c <http://www.gnu.org/licenses/>. |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 subroutine zch1dn(n,R,u,w,info) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 c purpose: given an upper triangular matrix R that is a Cholesky |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 c factor of a hermitian positive definite matrix A, i.e. |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 c A = R'*R, this subroutine downdates R -> R1 so that |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 c R1'*R1 = A - u*u' |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
24 c (complex version) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 c arguments: |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 c n (in) the order of matrix R |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 c R (io) on entry, the upper triangular matrix R |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 c on exit, the updated matrix R1 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 c u (io) the vector determining the rank-1 update |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 c on exit, u is destroyed. |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 c w (w) a workspace vector of size n |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 c NOTE: the workspace vector is used to store the rotations |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 c so that R does not need to be traversed by rows. |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 c |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 integer n,info |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 double complex R(n,n),u(n) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 double precision w(n) |
7725
7c9ba697a479
cosmetic fixes in QR & Cholesky updating codes
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
39 external ztrsv,zlartg,dznrm2 |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 double precision rho,dznrm2 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 double complex crho,rr,ui,t |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 integer i,j |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 |
7559
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
44 c quick return if possible |
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
45 if (n <= 0) return |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 c check for singularity of R |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 do i = 1,n |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 if (R(i,i) == 0d0) then |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 info = 2 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 return |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 end if |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 end do |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 c form R' \ u |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 call ztrsv('U','C','N',n,R,n,u,1) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 rho = dznrm2(n,u,1) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 c check positive definiteness |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 rho = 1 - rho**2 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 if (rho <= 0d0) then |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 info = 1 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 return |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 end if |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 crho = sqrt(rho) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 c eliminate R' \ u |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 do i = n,1,-1 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 ui = u(i) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 c generate next rotation |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 call zlartg(crho,ui,w(i),u(i),rr) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 crho = rr |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 end do |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 c apply rotations |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 do i = n,1,-1 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
72 ui = 0d0 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
73 do j = i,1,-1 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
74 t = w(j)*ui + u(j)*R(j,i) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
75 R(j,i) = w(j)*R(j,i) - conjg(u(j))*ui |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 ui = t |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 end do |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
78 end do |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
79 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
80 info = 0 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
81 end |