/************************* Program 3.A ****************************/ /* */ /************************************************************************/ /* 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 nmrv (n,h,q,s,u) /* The Numerov algorithm for the equation u"(x)+q(x)u(x)=s(x) as given in Eqs. (3.77)-(3.80) in the book. Copyright (c) Tao Pang 1997. */ int n; double h; double q[],s[],u[]; { int i; double g,c0,c1,c2,di,ut; g = h*h/12; for (i = 1; i < n-1; ++i) { c0 = 1+g*((q[i-1]-q[i+1])/2+q[i]); c1 = 2-g*(q[i+1]+q[i-1]+8*q[i]); c2 = 1+g*((q[i+1]-q[i-1])/2+q[i]); di = g*(s[i+1]+s[i-1]+10*s[i]); ut = c1*u[i]-c0*u[i-1]+di; u[i+1] = ut/c2; } }