c c Numerical Analysis: c The Mathematics of Scientific Computing c D.R. Kincaid & E.W. Cheney c Brooks/Cole Publ., 1990 c c Section 9.3 c c Example of Finite Difference Method c c c file: exs93.f c parameter (n=18) dimension v(0:n,0:n),x(0:n),y(0:n),u(0:n,0:n) c print * print *,' Finite Difference Method' print *,' Section 9.3, Kincaid-Cheney' print * print *,' error' c m = 200 nn = n+1 h = 1.0/nn do 2 i=0,n+1 x(i) = i*h y(i) = x(i) 2 continue do 3 i=0,n+1 v(i,0)=g(x(i),0.) v(i,n+1)=g(x(i),1.) v(0,i)=g(0.,y(i)) v(n+1,i)=g(1.,y(i)) 3 continue do 4 k=1,m do 4 j=1,n do 4 i=1,n v(i,j) = (v(i-1,j) + v(i+1,j) + v(i,j-1) + v(i,j+1))/4.0 4 continue xmax = 0.0 do 5 j=0,n do 5 i=0,n u(i,j) = g(x(i),y(j)) err = abs(v(i,j) - u(i,j)) if(err .gt. xmax) xmax = err 5 continue print 6,xmax c 6 format (5x,e13.6) stop end c real function g(x,y) data pi/3.14159 26535 89793/ g = (10.0e-4)*sinh(3.0*pi*x)*sin(3.0*pi*y) return end