~ubuntu-branches/ubuntu/intrepid/psicode/intrepid

« back to all changes in this revision

Viewing changes to src/lib/libqt/schmidt_add.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file schmidt_add.c
 
3
  \ingroup (QT)
 
4
*/
 
5
 
 
6
#include <stdio.h>
 
7
#include <math.h>
 
8
#include <libciomr/libciomr.h>
 
9
 
 
10
#define NORM_TOL 1.0E-5
 
11
 
 
12
/*!
 
13
** SCHMIDT_ADD(): Assume A is a orthogonal matrix.  This function Gram-Schmidt
 
14
** orthogonalizes a new vector v and adds it to matrix A.  A must contain
 
15
** a free row pointer for a new row.  Don't add orthogonalized v' if 
 
16
** norm(v') < NORM_TOL.
 
17
**
 
18
** David Sherrill, Feb 1994
 
19
**
 
20
** Arguments:
 
21
**    \param A    = matrix to add new vector to
 
22
**    \param rows = current number of rows in A 
 
23
**                  (A must have ptr for 'rows+1' row.)
 
24
**    \param cols = columns in A
 
25
**    \parm v     = vector to add to A after it has been made orthogonal 
 
26
**                  to rest of A
 
27
**
 
28
** Returns: 1 if a vector is added to A, 0 otherwise
 
29
** \ingroup (QT)
 
30
*/
 
31
int schmidt_add(double **A, int rows, int cols, double *v)
 
32
{
 
33
   double dotval, normval ;
 
34
   int i, I ;
 
35
 
 
36
   for (i=0; i<rows; i++) {
 
37
      dot_arr(A[i], v, cols, &dotval) ;
 
38
      for (I=0; I<cols; I++) v[I] -= dotval * A[i][I] ;
 
39
      }                 
 
40
 
 
41
   dot_arr(v, v, cols, &normval) ;
 
42
   normval = sqrt(normval) ;
 
43
 
 
44
   if (normval < NORM_TOL) 
 
45
      return(0) ;
 
46
   else {
 
47
      if (A[rows] == NULL) A[rows] = init_array(cols) ;
 
48
      for (I=0; I<cols; I++) A[rows][I] = v[I] / normval ;
 
49
      return(1) ;
 
50
      }
 
51
}
 
52
      
 
53