source: trunk/MagicSoft/slalib/svdcov.c@ 9488

Last change on this file since 9488 was 732, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#include "slalib.h"
2#include "slamac.h"
3void slaSvdcov ( int n, int np, int nc, double *w, double *v,
4 double *work, double *cvm )
5/*
6** - - - - - - - - - -
7** s l a S v d c o v
8** - - - - - - - - - -
9**
10** From the w and v matrices from the SVD factorization of a matrix
11** (as obtained from the slaSvd routine), obtain the covariance matrix.
12**
13** (double precision)
14**
15** Given:
16** n int number of rows and columns in matrices w and v
17** np int first dimension of array containing matrix v
18** nc int first dimension of array to receive cvm
19** *w double[n] nxn diagonal matrix w (diagonal elements only)
20** *v double[np][np] array containing nxn orthogonal matrix v
21**
22** Returned:
23** *work double[n] workspace
24** *cvm double[nc][nc] array to receive covariance matrix
25**
26** Reference:
27** Numerical Recipes, Section 14.3.
28**
29** Example call (note handling of "adjustable dimension" 2D arrays):
30**
31** double w[NP], v[NP][NP], work[NP], c[NC][NC];
32** int n;
33** :
34** slaSvdcov ( n, NP, NC, w, (double *) v, work, (double *) c );
35**
36** Last revision: 20 February 1995
37**
38** Copyright P.T.Wallace. All rights reserved.
39*/
40{
41 int i, j, k;
42 double s;
43 double *vi, *vj;
44 double *cvmi, *cvmj;
45
46
47 for ( i = 0; i < n; i++ ) {
48 s = w[i];
49 if ( s != 0.0 )
50 work[i] = 1.0 / ( s * s );
51 else
52 work[i] = 0.0;
53 }
54 for ( i = 0, vi = v, cvmi = cvm;
55 i < n;
56 i++, vi += np, cvmi += nc ) {
57 for ( j = 0, vj = v, cvmj = cvm;
58 j <= i;
59 j++, vj += np, cvmj += nc ) {
60 s = 0.0;
61 for ( k = 0; k < n; k++ ) {
62 s += vi[k] * vj[k] * work[k];
63 }
64 cvmi[j] = s;
65 cvmj[i] = s;
66 }
67 }
68}
Note: See TracBrowser for help on using the repository browser.