home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ANUMR5.ZIP / GELMTEST.C < prev    next >
C/C++ Source or Header  |  1991-03-11  |  2KB  |  93 lines

  1. /* OK */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <mem.h>
  7. #include <alloc.h>
  8. #include <dos.h>
  9.  
  10.  
  11. #include "anum.h"
  12. #include "sysio.h"
  13.  
  14. #define MAXDIM 8
  15.  
  16.  
  17. void affmat(int dim, double *matrix)
  18.  
  19.  
  20. {    int i,j;
  21.  
  22.     for (i=0;i<dim;i++)
  23.     {    for (j=0;j<dim;j++) printf("%8.4g ",*(matrix+i*dim+j));
  24.         putchar('\n');
  25.     }
  26. }
  27.  
  28.  
  29. void affvect(int dim, double *vect)
  30.  
  31.  
  32. {    int i;
  33.  
  34.     for (i=0;i<dim;)
  35.         printf("[%d] = %8.4g\n",++i,*(vect+i));
  36.  
  37. }
  38.  
  39.  
  40.  
  41. void results(int dim, double *vsol)
  42.  
  43. {    puts("Solution of A.X=B :");
  44.     affvect(dim,vsol);
  45.     printf("Core left : %ld bytes.\n",farcoreleft());
  46. }
  47.  
  48.  
  49.  
  50.  
  51. void main(void)
  52.  
  53.  
  54. {    double *mat_A, *vect_B, *vect_X;
  55.     int dim,i,j,errcode;
  56.  
  57.  
  58.     ena_m_beep();
  59.     puts("Test program for function gauss_elimination");
  60.     puts("-------------------------------------------\n");
  61.  
  62.     for (dim=1;dim<=MAXDIM;dim++)
  63.     {    mat_A=farcalloc(dim*dim,sizeof(double));
  64.         vect_B=farcalloc(dim,sizeof(double));
  65.         vect_X=farcalloc(dim,sizeof(double));
  66.  
  67.         for (i=0;i<dim;i++)
  68.         {    *(vect_B+i)=(double)(rand()%10)-5;
  69.             *(vect_X+i)=(double)(rand()%10)-5;
  70.             for(j=0;j<dim;j++)
  71.                 *(mat_A+i*dim+j)=(double)(rand()%10)-5;
  72.         }
  73.  
  74.         printf("\nMatrix order %d\n",dim);
  75.         puts("Matrix A");
  76.         affmat(dim,mat_A);
  77.         puts("\nVector B");
  78.         affvect(dim, vect_B);
  79.  
  80.         gauss_elimination(dim, mat_A, vect_B, vect_X, &errcode);
  81.         SYSMSG(errcode,stderr);
  82.  
  83.         results(dim,vect_X);
  84.         farfree(mat_A);
  85.         farfree(vect_X);
  86.         farfree(vect_B);
  87.     }
  88. }
  89.  
  90.  
  91.  
  92.  
  93.