Overview
Comment: | Put in pythag routine to compute z = sqrt(y^2 + z^2) (as in book) Save loop index l as ll when jumping from loop - using l itself is undefined |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
75f2ff6e3e4a0e5970103e4c6c3effdb |
User & Date: | gawthrop@users.sourceforge.net on 1998-08-12 11:08:03 |
Other Links: | branch diff | manifest | tags |
Context
1998-08-12
| ||
11:09:02 | Initial revision check-in: d9f0abbba3 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
11:08:03 |
Put in pythag routine to compute z = sqrt(y^2 + z^2) (as in book) Save loop index l as ll when jumping from loop - using l itself is undefined check-in: 75f2ff6e3e user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
11:05:33 |
Taken from NR share library nrpas13 as SVDCMP.PAS and renamed svdcmp.p check-in: 1d4b2f5f80 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/bin/trans/p/svdcmp.p from [98c452acd4] to [3f56cede4f].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | PROCEDURE svdcmp(VAR a: glmpbynp; m,n,mp,np: integer; VAR w: glnparray; VAR v: glnpbynp); { % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % $Id$ % % $Log$ % % Revision 1.1 1998/08/12 11:03:57 peterg % % Initial revision % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% } (* Programs using routine SVDCMP must define the types TYPE glnparray = ARRAY [1..np] OF real; glmpbynp = ARRAY [1..mp,1..np] OF real; glnpbynp = ARRAY [1..np,1..np] OF real; in the main routine. *) LABEL 1,2,3; CONST nmax=100; VAR | > > > > | | | > > > > > > > > > > > > > > > > > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | PROCEDURE svdcmp(VAR a: glmpbynp; m,n,mp,np: integer; VAR w: glnparray; VAR v: glnpbynp); { % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % $Id$ % % $Log$ % % Revision 1.2 1998/08/12 11:05:33 peterg % % Taken from NR share library nrpas13 as SVDCMP.PAS % % and renamed svdcmp.p % % % % Revision 1.1 1998/08/12 11:03:57 peterg % % Initial revision % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% } (* Programs using routine SVDCMP must define the types TYPE glnparray = ARRAY [1..np] OF real; glmpbynp = ARRAY [1..mp,1..np] OF real; glnpbynp = ARRAY [1..np,1..np] OF real; in the main routine. *) LABEL 1,2,3; CONST nmax=100; VAR nm,l,k,j,jj,its,i,ll : integer; z,y,x,scale,s,h,g,f,c,anorm : real; rv1 : ARRAY [1..nmax] OF real; FUNCTION pythag(a,b : real): real; VAR p,at,bt : REAL; BEGIN at:=abs(a); bt:=abs(b); IF at>bt THEN p:= at*sqrt(1.0+sqr(bt/at)) ELSE IF bt=0.0 THEN p := 0.0 ELSE p := bt*sqrt(1.0+sqr(at/bt)); pythag := p; END{pythag}; FUNCTION sign(a,b : real): real; BEGIN IF (b >= 0.0) THEN sign := abs(a) ELSE sign := -abs(a) END; FUNCTION max(a,b: real): real; BEGIN IF (a > b) THEN max := a ELSE max := b END; |
︙ | ︙ | |||
116 117 118 119 120 121 122 | END; anorm := max(anorm,(abs(w[i])+abs(rv1[i]))); END; FOR i := n DOWNTO 1 DO BEGIN IF (i < n) THEN BEGIN IF (g <> 0.0) THEN BEGIN FOR j := l TO n DO BEGIN | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | END; anorm := max(anorm,(abs(w[i])+abs(rv1[i]))); END; FOR i := n DOWNTO 1 DO BEGIN IF (i < n) THEN BEGIN IF (g <> 0.0) THEN BEGIN FOR j := l TO n DO BEGIN v[j,i] := (a[i,j]/a[i,l])/g; END; FOR j := l TO n DO BEGIN s := 0.0; FOR k := l TO n DO BEGIN s := s+a[i,k]*v[k,j] END; FOR k := l TO n DO BEGIN v[k,j] := v[k,j]+s*v[k,i] |
︙ | ︙ | |||
173 174 175 176 177 178 179 | END; a[i,i] := a[i,i]+1.0 END; FOR k := n DOWNTO 1 DO BEGIN FOR its := 1 TO 30 DO BEGIN FOR l := k DOWNTO 1 DO BEGIN nm := l-1; | | > > > > | > > > > | | > | | | > | | > | > | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | END; a[i,i] := a[i,i]+1.0 END; FOR k := n DOWNTO 1 DO BEGIN FOR its := 1 TO 30 DO BEGIN FOR l := k DOWNTO 1 DO BEGIN nm := l-1; IF ((abs(rv1[l])+anorm) = anorm) THEN BEGIN ll:=l; GOTO 2; END; IF nm>0 THEN {* Put in by me - see book *} IF ((abs(w[nm])+anorm) = anorm) THEN BEGIN ll:=l; GOTO 1 END; END; 1: c := 0.0; s := 1.0; FOR i := ll TO k DO BEGIN f := s*rv1[i]; IF ((abs(f)+anorm) <> anorm) THEN BEGIN g := w[i]; {**h := sqrt(f*f+g*g);**} h := pythag(f,g); w[i] := h; h := 1.0/h; c := (g*h); s := -(f*h); FOR j := 1 TO m DO BEGIN y := a[j,nm]; z := a[j,i]; a[j,nm] := (y*c)+(z*s); a[j,i] := -(y*s)+(z*c) END END END; 2: z := w[k]; IF (ll = k) THEN BEGIN IF (z < 0.0) THEN BEGIN w[k] := -z; FOR j := 1 TO n DO BEGIN v[j,k] := -v[j,k] END END; GOTO 3 END; IF (its = 30) THEN BEGIN writeln ('no convergence in 30 SVDCMP iterations'); readln END; x := w[l]; nm := k-1; y := w[nm]; g := rv1[nm]; h := rv1[k]; f := ((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y); {***g := sqrt(f*f+1.0); writeln(g);***} g := pythag(f,1.0); f := ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x; c := 1.0; s := 1.0; FOR j := ll TO nm DO BEGIN i := j+1; g := rv1[i]; y := w[i]; h := s*g; g := c*g; {**z := sqrt(f*f+h*h);**} z := pythag(f,h); rv1[j] := z; c := f/z; s := h/z; f := (x*c)+(g*s); g := -(x*s)+(g*c); h := y*s; y := y*c; FOR jj := 1 TO n DO BEGIN x := v[jj,j]; z := v[jj,i]; v[jj,j] := (x*c)+(z*s); v[jj,i] := -(x*s)+(z*c) END; {**z := sqrt(f*f+h*h);**} z := pythag(f,h); w[j] := z; IF (z <> 0.0) THEN BEGIN z := 1.0/z; c := f*z; s := h*z END; f := (c*g)+(s*y); |
︙ | ︙ | |||
261 262 263 264 265 266 267 | END; rv1[l] := 0.0; rv1[k] := f; w[k] := x END; 3: END END; | > | 294 295 296 297 298 299 300 301 | END; rv1[l] := 0.0; rv1[k] := f; w[k] := x END; 3: END END; |