home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ANUMR5.ZIP / EGNTJCBI.C < prev    next >
C/C++ Source or Header  |  1991-04-26  |  2KB  |  102 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 <conio.h>
  9. #include <dos.h>
  10.  
  11.  
  12. #include "anum.h"
  13. #include "sysio.h"
  14.  
  15. #define MAXDIM 8
  16.  
  17.  
  18.  
  19. void affmat(int dim, double *matrix)
  20.  
  21.  
  22. {    register int i,j;
  23.  
  24.     for (i=0;i<dim;i++)
  25.     {    for (j=0;j<dim;j++) printf("% 6lg ",*(matrix+i*dim+j));
  26.         putchar('\n');
  27.     }
  28. }
  29.  
  30.  
  31. void affvect(int dim, double *v)
  32.  
  33. {    register int i;
  34.  
  35.     for (i=0; i<dim; i++)
  36.     {    printf("% lf ",*(v+i));
  37.         if ((i+1)%6==0) putchar('\n');
  38.     }
  39.     putchar('\n');
  40. }
  41.  
  42.  
  43.  
  44. void results(int dim, double *valp, double *vectp, int errcode, int iter)
  45.  
  46. {       int i;
  47.  
  48.     SYSMSG(errcode,stderr);
  49.     puts("\nEigen values :");
  50.     affvect(dim, valp);
  51.     puts("Eigen vectors :");
  52.     for (i=0; i<dim; i++)
  53.         affvect(dim,vectp+i*dim);
  54.     printf("Iteration number : %d\n",iter);
  55.     printf("Core left : %ld bytes.\n",farcoreleft());
  56. }
  57.  
  58.  
  59.  
  60.  
  61. void main(void)
  62.  
  63.  
  64. {    double *matrix,tol,*valp,*mvectp;
  65.     int dim,i,j,errcode,maxiter,iter;
  66.  
  67.     tol=1e-10;
  68.     maxiter=200;
  69.  
  70.     clrscr();
  71.     printf("Test program for function jacobi\n");
  72.     sleep(2);
  73.     for (dim=1;dim<=MAXDIM;dim++)
  74.     {    matrix=farcalloc(dim*dim,sizeof(double));
  75.         mvectp=farcalloc(dim*dim,sizeof(double));
  76.         valp=farcalloc(dim,sizeof(double));
  77.  
  78.         for (i=0;i<dim;i++)
  79.             for(j=i; j<dim; j++)
  80.             {    *(matrix+i*dim+j)=(double)(rand()%100)-50;
  81.                 *(matrix+j*dim+i)=*(matrix+i*dim+j);
  82.             }
  83.  
  84.         clrscr();
  85.         printf("Matrix order : %d\n",dim);
  86.         affmat(dim,matrix);
  87.  
  88.  
  89.         jacobi(dim,matrix,maxiter,tol,valp,
  90.             mvectp,&iter,&errcode);
  91.  
  92.         results(dim,valp,mvectp,errcode,iter);
  93.         farfree(matrix);
  94.         farfree(valp);
  95.         farfree(mvectp);
  96.         delay(4000);
  97.     }
  98. }
  99.  
  100.  
  101.  
  102.