Line Jacobi (C Version)
#include
#include
# define N 52 /* for arrays with indices 0-51 in both dirs */
main()
{
double u[N][N],v[N][N],e[N][N];
double a[N],b[N],c[N],d[N],ratio;
double x,y,h,res,resmax,err,error;
int i,j,m,k;
double tol = .005;
/*
Line Jacobi algorithm for Laplace Difference Equation
*/
/* Initialize arrays and set boundary conditions */
h = 1.0/N;
for(i=0;i0;j--)
{
d[j]=(d[j]-c[j]*d[j+1])/b[j];
u[i][j] = d[j];
}
} /* end for i (the last row) */
/* write u into v to prepare for the next iteration */
for(i=1;i resmax) resmax = fabs(res);
err = e[i][j] - u[i][j];
if(fabs(err) > error) error = fabs(err);
}
}
printf("at iteration %d resmax = %f and error = %f\n",k,resmax,error);
} /* end for k */
} /* end main */