Thompson - Computing for Scientists and Engineers (523188), страница 76
Текст из файла (страница 76)
nThe series expansion method is practical if many small values of a are to be usedbut the same range of v is to be covered. Then it is practical to save these values forreuse when a is changed. For general-purpose use, direct integration of the functionin (10.65) is more appropriate.Program for direct integration of profileThe final computing part of our Voigt profile project is to integrate the Fourier transform expression directly, thereby being able to check the convergence of the expansion in powers of the width-ratio parameter a, (10.62), as it appears in the series(10.65) for H (a,v).Exercise 10.45Code and execute the trapezoid-rule program trap with the integrand from(10.65). Check the convergence of the program as a function of the input stepsize dx and number of steps Nx.
nFor dx = 0.05 and Nx = 100, I found agreement to four decimal places betweenthe series expansion and the numerical integration for a = 0.25 out to |v| = 2.A major lesson from our analysis of convolution of a Gaussian with a Lorentzian(calculation of the Voigt profile) is that the complexity of mathematical and numericalanalysis, and consequently of programming, can increase remarkably when thefunctions involved are changed in fairly simple ways. It is therefore also worthwhile to expend a reasonable effort in analysis of a problem before rushing to “giveit to the computer.” Even if the final results are primarily numerical, as for the VoigtREFERENCES ON FOURIER INTEGRAL TRANSFORMS419function, the initial analysis may lead to improved understanding of the mathematicsand science.Application to stellar spectraThe spectra of light emitted by stars and observed at the Earth may be used to characterize the plasma environment from which the light was emitted.
Allen’s book onatoms, stars, and nebulae, provides the astronomy and astrophysics background.The details are described in, for example, Chapter 9 of the book by Mihalas onstellar atmospheres, which has a comprehensive introduction to the subject of spectral-line absorption profiles and line broadening. Here is a schematic summary ofthe main ideas, sufficient to indicate the order of magnitude of the quantities used tocalculate Voigt profiles for stellar spectra.The simplest example is that of atoms radiating in a gas at temperature T.
Aspectral “line” of width is then Doppler-broadened because of the thermal agitationof the atoms, with some atoms moving towards the observer and some movingaway at the moment they emit light. For example, suppose that a spectral line suchas that for hydrogen (the predominant element in stars) is of Lorentzian line shapewith a FWHM of 0.01 nm at a wavelength of 500 nm. At T = 104K for hydrogen the width of the Maxwell-Boltzmann distribution describing the spread of atomvelocities in the plasma is about 4.3 × 10-5 times the speed of light.Under these conditions, the parameter for the Voigt profile, a, given by (10.62),is then about 0.25. The resulting Voigt profile is then that shown in Figure 10.11.It is approximately of Gaussian shape for v in the range -0.5 to 0.5, and thereforethe shape of this region of the spectral distribution is dominated by the temperaturedistribution in the stellar atmosphere.
In the wings of the distribution the profile becomes Lorentzian in shape and is affected by the natural line width of the emittingatoms plus effects such as collisions with electrons in the stellar plasma.For laboratory plasmas, such as in fusion-energy devices, measurements ofspectral-line broadening may be used to characterize properties such as the temperature of the major regions of the plasma that are emitting the detected light and otherelectromagnetic radiation. In such applications, as also in stellar atmospheres, thevery strong electric and magnetic fields also produce significant broadening of thespectral lines.REFERENCES ON FOURIER INTEGRAL TRANSFORMSAbramowitz, M., and I. A. Stegun, Handbook of Mathematical Functions, Dover,New York, 1964.Allen, L. H., Atoms, Stars, and Nebulae, Cambridge University Press, Cambridge,England, third edition, 1991.420FOURIER INTEGRAL TRANSFORMSBracewell, R.
N., The Fourier Transform and Its Applications, McGraw-Hill, NewYork, second edition, 1986.Churchill, R. V., Fourier Series and Boundary Value Problems, McGraw-Hill,New York, 1963.Dodd, J. N., Atoms and Light: Interactions, Plenum, New York, 1991.Hamming, R. W., Digital Filters, Prentice Hall, Englewood Cliffs, New Jersey,third edition, 1989.Ingard, K. U., Fundamentals of Waves and Oscillations, Cambridge UniversityPress, Cambridge, England, 1988.Mihalas, D., Stellar Attmospheres, W. H. Freeman, San Francisco, second edition,1978.Nussbaumer, H. J., Fast Fourier Transform and Convolution Algorithms, SpringerVerlag, New York, second edition, 1982.Pippasd, A.
B., The Physics of Vibration, Cambsidge University Press, Cambridge,England, 1988.Solomon, F., “Tomography: Three-Dimensional Image Reconstsruction,” UMAPModule 318, in UMAP Modules Tools for Teaching, COMAP, Arlington,Massachusetts, 1987, pp. 1 - 20.Previous HomeAPPENDIXTRANSLATING BETWEEN C, FORTRAN,AND PASCAL LANGUAGESHere, in tabular and example form, is an outline of the main differences between C,Fortran, and Pascal. It is intended to help you overcome the barrier to translatingbetween these three languages, rather than to substitute for learning thoroughly thelanguage of your choice. In particular (as discussed in Section 1.2), the sampleprograms in this book use only the parts of C relating to numerical applications,which is a limited subset of the full language.If you wish to become a competent programmer in the C language, the References on Learning and Using C at the end of Chapter 1 should be helpful.
Thebook by Gehani and that by Müldnes and Steele, are suitable if you are experiencedin other computer languages. Kerrigan’s book is specifically aimed to help thetransition from Fortran to C, while the book by Shammas introduces C to Pascalprogrammers.The material following summarizes the aspects of C language that are used inthis book, together with workable counterparts in Fortran and C. The C examplesof code segments are drawn from the sample programs, and I indicate in which program a similar code segment can be found.
The Fortran and Pascal code segmentsare likely to be correct, but they have not been tested by compiling them withincomplete programs. I have not attempted to indicate correspondences between thethree languages for topics that are highly dependent on the computing environment,such as file declarations.In the following table the items in italics are generic names that are substituted byactual names, as shown in the examples.423Next424APPENDIXCFortranPascalOverall Structure and Procedure Declarationsmain().function().void function()..Program name.function().subroutine name()..program name;.function();.procedure();main programExample; See Program 2.1Data Type Declarationsdouble name ;real nameint name ;integer namedouble array [SIZE]; real array (SIZE)int array [SIZE];int array (SIZE)char name;characternamevar name : real;var name : integer;var array [l..
SIZE ]of real;var array [l.. SIZE ]of integer;var name : char;Example; Program 3.1double rmin,dr;int nterms,kmax;real rmin,drinteger nterms,kmaxvar rmin,dr: real;var nterms,kmax:integer;Input and OutputConsole:scanf (input list );printf( format,output list);read( input list );read(*, format )input listwrite(*, format )output listwrite (outputlist);write(*,* )'Input x1'read(*,*) x1write('Input x1');read(x1);Example: Program 2.1printf("Input x1 ");scanf("%lf",x1);APPENDIXC425PascalFortranFiles:FILE *file name ;FILE *fopen();fscanf (fin, format,input list );fprintf (fout,format,output list);read(unit, format )get (pointer tofile item );input listwrite(unit, format )output listput (pointer tofile item );Example; Program 7.1FILE *fin,fout;FILE *fopen();fprintf(fout,"%lf",Din);(Require system-dependent file allocation)write(10,F10.2)Dinput(Din);Control Structureswhilewhile (condition){action }while (condition )dobegin action end;Example: Program 2.1while (xl != 0 ){printf ("Input xl:");while (xl <> 0 ) dobeginwriteln('Input xl');end;i fif (condition){action }if (condition ) thenactionif (condition ) thenbegin action end;Example: Program 2.1if ( xl == 0 ){ printf ("End");if ( x1.EQ.0 ) thenif(xl=0)write (*,*) 'End' beginwriteln ("End");end;426APPENDIXCif..FortranPascalelseif (condition){action 1}else{action 2}if (condition) thenaction 1elseaction 2if (condition) thenbeginaction 1;end;elsebeginaction 2;end;if ( den.EQ.0) thenx1d2 = 0;elsex1d2 =(x1*x2+y1*y2)/denif(den=O)beginx1d2 := 0;end;elsebeginx1d2 :=(x1*x2+y1*y2)/den;end;Example: Program 2.1if ( den == 0 ){ x1d2 = 0;}else{ x1d2 =(x1*x2+y1*y2)/den;forfor (loop condition) (sometimes Do loop){ action}for loopcondition dobegin action end;Example: Program 3.1for(k=l;k<=kmax;k++){term = r*term;sun= sum+term;}do 2 k=l,krmax,lterm = r*termsum= sum+term2 continuefor k:=l to kmax dobeginterm := r*term;sum := sum+term;end;APPENDIXFortranPascalgoto(st 1,st 2,.),expressionst 1 action1st 2 action2case condition of1: action 1;2: action 2;C427switchswitch (expression){case constant 1:{action1}; break;case constant 2:(action2); break;Ddefault: {action};st 1 & st 2 arestatement numbersExample: Program 3.4switch (choice){case 1:series=PSexp;break;case 2:series=PScos;break;}goto (1,2),choiceseries=PSexpseries=PScoscase choice of1: series :=PSexp;2: series :=PScos;**y(Requires function)Program OperatorsArithmetic Powerpow (x,y)Assignmentvariable 1 =expression ;Increment & Decrement++ increment by 1-- decrement by 1variable 1 =expressionvariable 1: =expression ;428APPENDIXCPascalFortranArithmetic CompareEqual to;Not equal to;Less than;Less than or equal;Greater than;Greater than or equal;==!=<<=>>=.EQ..NE..LT..LE..GT..GE.=<><<=>>=Logical OperatorsAnd;Or;Not;&&||!.AND..OR..NOT.ANDORNOTPrevious Home NextEPILOGUENow that you have used this guidebook to learn and psactise mathematical analysis,numerics, and their applications to the sciences and engineering, I hope that you willbe eager to explore further afield, applying your new understanding to pose andsolve problems in your own field of endeavor.As I emphasized in Chapter 1, comprehension of the basics of analytical andnumerical techniques is necessary before one travels the smooth highways providedby programming systems.
Now that you have such comprehension, many of yourcomputing and graphics tasks can be handled by systems such as Wolfram’sMathematica. The book of Mathematica examples by Abell and Braselton willalso help you acquire proficiency in using this system. If you are usingworkstations, the book by Landau and Fink should provide useful guidance.If in your computing you wish to work at the programming level (to make adistinction that was emphasized in Section 1.2), the books of numerical recipes byPress et al. are convenient. They are available with C code and also in Fortran orPascal. For the programming of mathematical functions of the kind described in thecompendium by Absamowitz and Stegun, the handbook and programs provided byBaker are suitable.Tomorrow to fsesh fields and pastures new.ReferencesAbell, M.