Advertisement
Guest User

Henrique Miranda

a guest
Jan 20th, 2009
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. #define POINTS 1.8
  7. #define DIM 100
  8. #define MDIM 50
  9.  
  10. int main()
  11. {
  12.     //int dim = 1000, mdim = dim/2;
  13.     float mat[DIM][DIM], vel, a;
  14.     double num, den, delta = 1;
  15.     int i = 0, h = 0, it = 0;
  16.     //char string[6];
  17.     //FILE *fp;
  18.    
  19.     //semente
  20.     mat[MDIM][MDIM] = 0;
  21.  
  22.     //desenhar pontos
  23.     for(a = .5;  a < POINTS; a+=.01)
  24.     {
  25.        
  26.         //preencher a grelha com 1's nas fronteiras
  27.         for(i = 0; i < DIM; i++)
  28.         {
  29.             mat[i][0] = 1;
  30.             mat[0][i] = 1;
  31.             mat[99][i] = 1;
  32.             mat[i][99] = 1;
  33.         }
  34.        
  35.         //preencher a grelha com .8 no resto do tabuleiro
  36.         for(i = 1; i < (DIM - 1); i++)
  37.         {
  38.              for(h = 1; h < (DIM - 1); h++)
  39.              {
  40.                  mat[i][h] = .8;
  41.              }
  42.         }
  43.        
  44.         //processo
  45.         while (delta > .005)
  46.         {
  47.             for(i = 0; i < DIM; i++)
  48.             {
  49.                 for(h = 0; h < DIM; h++)
  50.                 {
  51.                     if (mat[i][h] != 0 && mat[i][h] != 1)
  52.                     {
  53.                         vel = ((mat[i+1][h] + mat[i-1][h] + mat[i][h+1] + mat[i][h-1]) / 4) - mat[i][h];
  54.                         mat[i][h] += a*vel;
  55.                     }
  56.                
  57.                     den += (mat[i][h]) * (mat[i][h]);
  58.                     num += vel*vel;
  59.                 }
  60.             }
  61.            
  62.         it += 1;
  63.         delta = sqrt (num / den);
  64.        
  65.         //imprimir para ficheiro
  66.         /*sprintf(string, "file%d.dat", c);
  67.         fp=fopen(string,"w");
  68.        
  69.         for(i = 0; i < DIM; i++)
  70.         {
  71.             for(h = 0; h < DIM; h++)
  72.             {
  73.                 fprintf(fp,"%d %d %f\n", i, h, mat[i][h]);
  74.             }
  75.         }
  76.        
  77.         fclose(fp);*/
  78.        
  79.         }
  80.        
  81.         printf("%f %d\n", a, it);
  82.         it = 0;
  83.         delta = 1;
  84.  
  85.     }
  86.    
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement