c17-3 (779603), страница 4
Текст из файла (страница 4)
Onlycolumns jm1-jm2,jmf are affected by the prior results. red is used internally by solvde.{int loff,l,j,ic,i;float vx;loff=jc1-jm1;ic=ic1;Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited.
To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).for (i=ie1;i<=ie2;i++) {Implicit pivoting, as in §2.1.big=0.0;for (j=je1;j<=je2;j++)if (fabs(s[i][j]) > big) big=fabs(s[i][j]);if (big == 0.0) nrerror("Singular matrix - row all 0, in pinvs");pscl[i]=1.0/big;indxr[i]=0;}for (id=ie1;id<=ie2;id++) {piv=0.0;for (i=ie1;i<=ie2;i++) {Find pivot element.if (indxr[i] == 0) {big=0.0;for (j=je1;j<=je2;j++) {if (fabs(s[i][j]) > big) {jp=j;big=fabs(s[i][j]);}}if (big*pscl[i] > piv) {ipiv=i;jpiv=jp;piv=big*pscl[i];}}}if (s[ipiv][jpiv] == 0.0) nrerror("Singular matrix in routine pinvs");indxr[ipiv]=jpiv;In place reduction.
Save column ordering.pivinv=1.0/s[ipiv][jpiv];for (j=je1;j<=jsf;j++) s[ipiv][j] *= pivinv;Normalize pivot row.s[ipiv][jpiv]=1.0;for (i=ie1;i<=ie2;i++) {Reduce nonpivot elements in column.if (indxr[i] != jpiv) {if (s[i][jpiv]) {dum=s[i][jpiv];for (j=je1;j<=jsf;j++)s[i][j] -= dum*s[ipiv][j];s[i][jpiv]=0.0;}}}}jcoff=jc1-js1;Sort and store unreduced coefficients.icoff=ie1-je1;for (i=ie1;i<=ie2;i++) {irow=indxr[i]+icoff;for (j=js1;j<=jsf;j++) c[irow][j+jcoff][k]=s[i][j];}free_vector(pscl,ie1,ie2);free_ivector(indxr,ie1,ie2);772Chapter 17.Two Point Boundary Value Problems}“Algebraically Difficult” Sets of Differential EquationsRelaxation methods allow you to take advantage of an additional opportunity that, whilenot obvious, can speed up some calculations enormously.
It is not necessary that the setof variables yj,k correspond exactly with the dependent variables of the original differentialequations. They can be related to those variables through algebraic equations. Obviously, itis necessary only that the solution variables allow us to evaluate the functions y, g, B, C thatare used to construct the FDEs from the ODEs. In some problems g depends on functions ofy that are known only implicitly, so that iterative solutions are necessary to evaluate functionsin the ODEs. Often one can dispense with this “internal” nonlinear problem by defininga new set of variables from which both y, g and the boundary conditions can be obtaineddirectly. A typical example occurs in physical problems where the equations require solutionof a complex equation of state that can be expressed in more convenient terms using variablesother than the original dependent variables in the ODE.
While this approach is analogous toperforming an analytic change of variables directly on the original ODEs, such an analytictransformation might be prohibitively complicated. The change of variables in the relaxationmethod is easy and requires no analytic manipulations.CITED REFERENCES AND FURTHER READING:Eggleton, P.P. 1971, Monthly Notices of the Royal Astronomical Society, vol. 151, pp. 351–364.[1]Keller, H.B. 1968, Numerical Methods for Two-Point Boundary-Value Problems (Waltham, MA:Blaisdell).Kippenhan, R., Weigert, A., and Hofmeister, E. 1968, in Methods in Computational Physics,vol.
7 (New York: Academic Press), pp. 129ff.17.4 A Worked Example: Spheroidal HarmonicsThe best way to understand the algorithms of the previous sections is to seethem employed to solve an actual problem. As a sample problem, we have selectedthe computation of spheroidal harmonics. (The more common name is spheroidalangle functions, but we prefer the explicit reminder of the kinship with sphericalharmonics.) We will show how to find spheroidal harmonics, first by the methodof relaxation (§17.3), and then by the methods of shooting (§17.1) and shootingto a fitting point (§17.2).Spheroidal harmonics typically arise when certain partial differentialequations are solved by separation of variables in spheroidal coordinates. Theysatisfy the following differential equation on the interval −1 ≤ x ≤ 1: dSm2d(1 − x2 )+ λ − c2 x 2 −S=0(17.4.1)dxdx1 − x2Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use.
Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).for (j=jz1;j<=jz2;j++) {Loop over columns to be zeroed.for (l=jm1;l<=jm2;l++) {Loop over columns altered.vx=c[ic][l+loff][kc];for (i=iz1;i<=iz2;i++) s[i][l] -= s[i][j]*vx;Loop over rows.}vx=c[ic][jcf][kc];for (i=iz1;i<=iz2;i++) s[i][jmf] -= s[i][j]*vx;Plus final element.ic += 1;}.















