#!/usr/local/bin/tcc -run #include #include void out(float dt, int n, int JJ, float u[]){ int j; printf("%6.2f |", dt*n); for(j=0; j<=JJ; j++){ printf("%6.3f ", u[j]); } printf("\n"); } int main(void){ int NM=31; int JJ=30; float dx=3.0/JJ; float dt=0.01; int NN=30; float c=0.5; float r=c*dt/dx; int j,n; float x[NM],f[NM],u[NM],uu[NM]; for(j=0; j<=JJ; j++){ f[j]=sin(6.0*x[j]); if(x[j]>4.0*atan(1.0)/3.0) f[j]=0.0; } for(j=0; j<=JJ; j++){ u[j]=f[j]; uu[j]=f[j]; } out(dt,0,JJ,u); for(n=1; n<=NN; n++){ for(j=1; j<=JJ; j++){ uu[j]=(1-r)*u[j]+r*u[j-1]; } out(dt,n,JJ,uu); for(j=0; j<=JJ; j++){ u[j]=uu[j]; } } return 0; }