Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #define POINTS 1.8
- #define DIM 100
- #define MDIM 50
- int main()
- {
- //int dim = 1000, mdim = dim/2;
- float mat[DIM][DIM], vel, a;
- double num, den, delta = 1;
- int i = 0, h = 0, it = 0;
- //char string[6];
- //FILE *fp;
- //semente
- mat[MDIM][MDIM] = 0;
- //desenhar pontos
- for(a = .5; a < POINTS; a+=.01)
- {
- //preencher a grelha com 1's nas fronteiras
- for(i = 0; i < DIM; i++)
- {
- mat[i][0] = 1;
- mat[0][i] = 1;
- mat[99][i] = 1;
- mat[i][99] = 1;
- }
- //preencher a grelha com .8 no resto do tabuleiro
- for(i = 1; i < (DIM - 1); i++)
- {
- for(h = 1; h < (DIM - 1); h++)
- {
- mat[i][h] = .8;
- }
- }
- //processo
- while (delta > .005)
- {
- for(i = 0; i < DIM; i++)
- {
- for(h = 0; h < DIM; h++)
- {
- if (mat[i][h] != 0 && mat[i][h] != 1)
- {
- vel = ((mat[i+1][h] + mat[i-1][h] + mat[i][h+1] + mat[i][h-1]) / 4) - mat[i][h];
- mat[i][h] += a*vel;
- }
- den += (mat[i][h]) * (mat[i][h]);
- num += vel*vel;
- }
- }
- it += 1;
- delta = sqrt (num / den);
- //imprimir para ficheiro
- /*sprintf(string, "file%d.dat", c);
- fp=fopen(string,"w");
- for(i = 0; i < DIM; i++)
- {
- for(h = 0; h < DIM; h++)
- {
- fprintf(fp,"%d %d %f\n", i, h, mat[i][h]);
- }
- }
- fclose(fp);*/
- }
- printf("%f %d\n", a, it);
- it = 0;
- delta = 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement