~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libciomr/hess_elim.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
#include <math.h>
 
2
 
 
3
#define SWAP(g,h) {y=(g);(g)=(h);(h)=y;}
 
4
 
 
5
hess_elim(double **a, int n)
 
6
{
 
7
   int m,j,i;
 
8
   double y,x;
 
9
 
 
10
   for(m=1; m < n-1 ; m++) {
 
11
      x=0.0;
 
12
      i=m;
 
13
      for(j=m; j < n ; j++) {
 
14
         if(fabs(a[j][m-1]) > fabs(x)) {
 
15
            x=a[j][m-1];
 
16
            i=j;
 
17
            }
 
18
         }
 
19
      if(i!=m) {
 
20
         for(j=m-1; j < n ; j++) SWAP(a[i][j],a[m][j])
 
21
         for(j=0; j < n ; j++) SWAP(a[j][i],a[j][m])
 
22
         }
 
23
      if(x) {
 
24
         for(i=m+1; i < n ; i++) {
 
25
            if(y=a[i][m-1]) {
 
26
               y /= x;
 
27
               a[i][m-1]=y;
 
28
               for(j=m; j < n ; j++) a[i][j] -= y*a[m][j];
 
29
               for(j=0; j < n; j++) a[j][m] += y*a[j][i];
 
30
               }
 
31
            }
 
32
         }
 
33
      }
 
34
   }