Você está na página 1de 1

#include <stdio.

h>
#include <math.h>
#include <time.h>
#define X 10000
#define T 10000
static double U[X+1][T+2]; // declare matrix U
int main()
{
int t, x;
double L= 0.345678, S;
// initialize positions of matrix U
for (x=1; x<X; x++) {
U[x][0] = sin((double)x*M_PI/(double)X);
U[x][1] = U[x][0]*cos(M_PI/(double)T);
}
for (t=0; t<=T+1; t++) {
U[0][t] = 0.0;
U[X][t] = 0.0;
}
// Program Body
for (t=2; t<=T+1; t++){
for (x=1; x<X; x++){
U[x][t] = 2.0*(1.0-L)*U[x][t-1]+L*U[x+1][t-1]+L*U[x-1][t-1]-U[x][t-2];
}
}
// obtain checksum of final state
S = 0.0; //initialize S
for (x=0; x<=X; x++) {
S += U[x][T+1];
}
printf("CheckSum = %e\n", S);
return 0;
}

Você também pode gostar