Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/Math/Vector/NotDone/Gauss/test_gaussj.cpp

Go to the documentation of this file.
00001 #include <time.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 void main()
00006 {
00007   int i, j, k, n = 2000, n2 = n * n, t0, t = 0;
00008 
00009   double *A = (double *) malloc(n2 * sizeof(double));
00010 
00011   double *a[4096], b[4096], x[4096], e, ee; a[0] = A;
00012 
00013   for (i = 1; i < n; i++) a[i] = a[i-1] + n;
00014 
00015   srand(clock());
00016 
00017   for (i = 0; i < n2; i++) A[i] = 0.0;
00018 
00019   for (i = 0; i < n; i++) a[i][i] = 1.0;
00020 
00021   for (k = n; k < 6000; k++)
00022     {
00023       do i = rand() * n / 32768, j = rand() * n / 32768; while (i <= j || a[i][j]);
00024 
00025       a[i][j] = (1 + rand()) / 32768.0;
00026     }
00027 
00028   for (k = 0; k < n2; k++)
00029     {
00030       i = rand() * n / 32768; j = rand() * n / 32768;
00031 
00032       e = a[i][j]; a[i][j] = a[j][i]; a[j][i] = e;
00033     }
00034 
00035   for (k = i = 0; i < n; i++) for (j = 0; j < n; j++) if (a[i][j]) k++;
00036 
00037   printf("k = %d\n", k);
00038 
00039   for (i = 0; i < n; i++) x[i] = rand() / 32767.0;
00040 
00041   for (i = 0; i < n; i++) for (b[i] = j = 0; j < n; j++) b[i] += a[i][j]*x[j];
00042 
00043   t0 = clock();
00044   a[n] = b; if (!gaussj(a, n, 1, 1e-7)) return;
00045   t += clock() - t0;
00046 
00047   for (e = i = 0; i < n; i++) if ((ee = fabs(x[i] - b[i])) > e) e = ee;
00048 
00049   printf("Error = %e, Time = %d\n", e, t);
00050 
00051   free(A);
00052 }

Generated on Sun Oct 14 18:46:15 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001