~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

Viewing changes to src/lib/libqt/schmidt.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file
 
3
  \brief Gram-Schmidt orthogonalize a set of vectors
 
4
  \ingroup QT
 
5
*/
 
6
 
 
7
#include <cstdio>
 
8
#include <cstdlib>
 
9
#include <cmath>
 
10
#include <libciomr/libciomr.h>
 
11
 
 
12
extern "C" {
 
13
        
 
14
/* #define STANDALONE */
 
15
 
 
16
/*!
 
17
** SCHMIDT(): Gram-Schmidt orthogonalize a set of vectors
 
18
**
 
19
** Assume we're orthogonalizing the ROWS, since in C
 
20
** a vector is usually a row more often than a column.
 
21
**
 
22
** David Sherrill, Feb 1994
 
23
**
 
24
** \param A    = matrix to orthogonalize (matrix of doubles)
 
25
** \param rows = rows of A 
 
26
** \param cols = columns of A
 
27
**
 
28
** Returns: none
 
29
** \ingroup QT
 
30
*/
 
31
void schmidt(double **A, int rows, int cols, FILE *outfile)
 
32
{
 
33
   double *tmp;
 
34
   double normval, dotval;
 
35
   int i, j;
 
36
   register int I;
 
37
 
 
38
   /* initialize working array */
 
39
   tmp = init_array(cols);
 
40
  
 
41
   /* always take the first vector (normalized) as given */
 
42
   dot_arr(A[0], A[0], cols, &normval) ; /* normval = dot (A0 * A0) */
 
43
   normval = sqrt(normval) ;
 
44
 
 
45
   for (i=0; i<cols; i++) A[0][i] /= normval; 
 
46
 
 
47
   /* now, one at a time, get the new rows */
 
48
   for (i=1; i<rows; i++) {
 
49
      for (I=0; I<cols; I++) tmp[I] = A[i][I] ;
 
50
      for (j=0; j<i; j++) {
 
51
         dot_arr(A[i], A[j], cols, &dotval) ; 
 
52
         for (I=0; I<cols; I++) tmp[I] -= dotval * A[j][I];
 
53
         }
 
54
      dot_arr(tmp, tmp, cols, &normval);
 
55
      normval = sqrt(normval);
 
56
      /* fprintf(outfile,"\n norm[%d] = %20.15f\n",i, (1.0/normval));
 
57
      fflush(outfile); */
 
58
      for (I=0; I<cols; I++) A[i][I] = tmp[I] / normval; 
 
59
      }
 
60
 
 
61
   free(tmp);
 
62
 
 
63
}
 
64
 
 
65
 
 
66
 
 
67
#ifdef STANDALONE
 
68
main()
 
69
{
 
70
   FILE *outfile ;
 
71
   double **mat, **mat_copy, **mat_x_mat ;
 
72
   void schmidt(double **A, int rows, int cols) ;
 
73
 
 
74
   mat = init_matrix(3, 3) ;
 
75
   mat_copy = init_matrix(3, 3) ;
 
76
   mat_x_mat = init_matrix(3, 3) ;
 
77
   mat[0][0] = 1.0 ; mat[0][1] = 0.0 ; mat[0][2] = 1.0 ;
 
78
   mat[1][0] = 1.0 ; mat[1][1] = -1.0 ; mat[1][2] = 0.0 ;
 
79
   mat[2][0] = 0.0 ; mat[2][1] = 0.0 ; mat[2][2] = 0.5 ;
 
80
 
 
81
   ffile(&outfile, "output.dat", 0) ;
 
82
   fprintf(outfile, "Matrix before Gram-Schmidt process\n") ;
 
83
   print_mat(mat,3,3,outfile) ;
 
84
   schmidt(mat,3,3) ;
 
85
   fprintf(outfile, "\nMatrix after Gram-Schmidt process\n") ;
 
86
   print_mat(mat,3,3,outfile) ;
 
87
 
 
88
   fprintf(outfile, "\nTest A * A = \n") ;
 
89
 
 
90
   mmult(mat, 0, mat, 1, mat_x_mat, 0, 3, 3, 3, 0) ;
 
91
   print_mat(mat_x_mat,3,3,outfile) ;
 
92
 
 
93
   free_matrix(mat,3) ;
 
94
   free_matrix(mat_copy,3) ;
 
95
   free_matrix(mat_x_mat,3) ;
 
96
 
97
#endif
 
98
 
 
99
} /* extern "C" */