/************************* Program 6.2 ****************************/ /* */ /************************************************************************/ /* Please Note: */ /* */ /* (1) This computer program is written by Tao Pang in conjunction with */ /* his book, "An Introduction to Computational Physics," published */ /* by Cambridge University Press in 1997. */ /* */ /* (2) No warranties, express or implied, are made for this program. */ /* */ /************************************************************************/ #include #include void rxln (fn,dn,s,n,p,h) /* Subroutine performing one iteration of Relaxation for the one-dimensional stationary diffusion equation. DN is the diffusion coefficient shifted half step towards x=0. Copyright (c) Tao Pang 1997. */ int n; double p,h; double fn[],dn[],s[]; { int i; double h2,q; h2 = h*h; q = 1-p; for (i = 1; i < n-1; ++i) { fn[i] = q*fn[i]+p*(dn[i+1]*fn[i+1]+dn[i]*fn[i-1]+h2*s[i])/(dn[i+1]+dn[i]); } }