8
#include <libciomr/libciomr.h>
10
#define NORM_TOL 1.0E-5
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.
18
** David Sherrill, Feb 1994
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
28
** Returns: 1 if a vector is added to A, 0 otherwise
31
int schmidt_add(double **A, int rows, int cols, double *v)
33
double dotval, normval ;
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] ;
41
dot_arr(v, v, cols, &normval) ;
42
normval = sqrt(normval) ;
44
if (normval < NORM_TOL)
47
if (A[rows] == NULL) A[rows] = init_array(cols) ;
48
for (I=0; I<cols; I++) A[rows][I] = v[I] / normval ;