physics by computer programming physical problems using mathematica and c.pdf

299
w. Kinzel/G. Reents Ie ut Programming Physical Problems W .... Using Mathematica® and C Springer

Upload: hesam-ahmadian

Post on 03-Feb-2016

63 views

Category:

Documents


20 download

TRANSCRIPT

  • w. Kinzel/G. Reents

    Ieb~

    utProgramming Physical Problems W....Using Mathematica and C

    Springer

  • Using Mathematica and C

    Translated b Martin CIaus and Bever! Freeland-Claus

    )

    With 88 Figures) 33 Exercises and a CD-ROMContaining Programs and Graphics Routines for PCs

    . ~ .

  • Prof. Dr. Wolfgang Kinzel..... r-. r-." ....

    Dr. Martin Clajusr-..... 1 ~ 1 .~..

    rl tV.-UU:.G. UI. Ut:UI~ ... Uf. ve; ve;lj' ~, -....,.vi.]USInstitut fUr Theoretische physikUniversiUit WiirzburgAm HublandD-97074 Wiirzburg

    Deot. of Physics & AstronomvUCLABox 951547Los Angeles, CA 90095-1547, USA

    e-maIl: e-maIl:[email protected]@physik.uni-wuerzburg.de

    c1a}[email protected]

    The cover picture shows a space-time diagram of the probability of presence of a quan-tum particle in a square-well potential.

    This American edition has been revised bv the authors. The book was oriQ:inallv oublishedin German: W. Kinzel, G. Reents: Physik per Computer, Spektrum Akademischer Verlag,Heidelberg 1996

    CIP data applied forDie Deutsche Bibliothek - CIP-EinheitsaufnahmePhysics by computer: programming physical problems using Mathematica and C; with 33 exercises and a CD-ROMcontaining programs and graphics routines for PCs and workstations; Mathematica 3.0 compatible I WolfgangKinzel; Georg Reents. Trans\. by Martin Clajus and Beverly Freeland-Clajus. - Berlin; Heidelberg; New York;Barcelona; Budapest; Hong Kong; London; Milan; Paris; Santa Clara; Singapore; Tokyo: Springer.Einheitssacht.: Physik per Computer rCD'" v

    This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned,specifically the rights of translation, reprinting. reuse of illustrations, recitation, broadcasting, reproduction onmicrofilm or in any other way, and storage in data banks. Duplication of this publication or parts thereof ispermitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and

    (nr .. N' ...... d ;".,,,,,. ]"A frnrn . \7...1. . "rA \;"],,!A fnr ..n,JAP .hA

    Springer-Verlag Berlin Heidelberg 1998Printed in Germany

    Mathematica is a rel!istered trademark bv Wolfram Research, Inc.

    uoes nor implY' even in. . .

    ine .~se 01 ge~eral .,..., name~:. . names. r ,en;. In mls.............. vu .., v, 1-'............ , , u 1-" HV'" ,....

    and therefore free for general use.

    Please note: Before using the programs in this book, please consult the technical manuals provided by themanufacturer of the computer, and of any plug-in boards, to be used.The authors and the publisher accept no legal

    . .. . .. ..

    :espUnSllJ~~lY lUI any ~aust:u lJy : ust: UI lilt: .1:. 'UI~ v llt:rt:I~:;'" ...~ ..~. . '" ~,,~ v~~.. ,~~.~~ ..... ~~.~. ,~~~.. v ..~. "V .v....~. ...~ ...~l ....

    function correctly. The programs on the enclosed CD-ROM are under copyright protection and may not bereproduced without written permission by Springer-Verlag. One copy of the programs may be made as a back-up.but all further copies offend copyright law.

    ~Uver uesigll: I\.UIll

  • Preface

    For some apparently simple physical models there are only numerical answersso far. We know universal laws that any high school student can reproduce on

    ? .

    works, combinatorial optimization, biological evolution, formation of fractalstructures, and self-organized criticality are just some of the topics from the

    This book evolved out of lectures at the University of Wiirzburg, Ger-many, for physics majors after their fourth semester - those having completedthe introductor c r w i

  • VI Preface

    ." . " ... ~ ~ ." ..1. ~ ,~ ~~ ~I. ~ ..1 ~ ..1 ~ 1""".1 OJ.'-'O r , oVJ.J.J.'-' v... 'H J.J.J.'-'J.J. ....... '-' .... u UJ.J.'-' uo '-'~o'-' v ... , u.J.J.~ UJ. J.~O

    to SOlve tnem wltn SImple aJgoritnms.One goal is to encourage our readers to do their own programming. Al-

    though a CD-ROM with finished programs is enclosed with the book, they areA .' . --~ .not meant as user-rnenOlY experimental environments. we nope tnat insteaa

    they can be taken as a starting-point, and we encourage our readers to mod-ify them, or better yet to rewrite them more efficiently. Exercises accompanyevery section of this introductory book.

    We have received suggestions from many colleagues and students, to whomUTO UTlc:!h tn n11l" th~n1rc:! Wo ll1ro 11 tn 1\11" Rlohl

    .. "C .,

    H. Dietz, A. Engel, A. Freking, Th. Hahn, W. Hanke, G. Hildebrand, A. Jung,A. Karch, U. Krey, B. Lopez, J. Nestler, M. Opper, M. Schreckenberg, andn n n- Con"",..; ..1 th:lnk~ uo to t.hp. 10"" 11 . . ,. . ........ T I. r....

    .... ....

    .... .. ..

    1 1 . .1.1. V, .:L 1\ If. "..,. .... .1.~~

    'C ""'.~ C .... .. .... ~"'9' 'C , J.'.La... IIJ.J.J. UJ.J.~on Unix, and Ursula Eitelwein typed the manuscript of this book in UTEX.Finally we would like to thank Martin Clajus for valuable suggestions in the

    . .. .1.1. ., .. . T':' ......v .. ""

    .... IIJ.J...O J.J.""V....

    .

    TTT. TrT J~ . 'V.:... _~l'0 '.

    '" 07'07 ..... U 'UN,",U

    July, 1997 Georg Reents

  • Contents

    or .. . .................................................... ~

    1. Functions . Mathematica 3In ...............................1 1 ..,. . ~- 'I A. ...............................

    4 .... .-n1 .... T ,. T"Io 1 1 ,.

    L~ ~lle 1... .I. ............................... u

    1.3 Fourier Transformations ................................. 131.4 Smoothing of Data ..................................... 204 .. .... T ,. ...... nnLtJ .1' .I'lL .......................................... ~tJ

    1.6 Multlpole ~xpanslOn .................................... 3U1.7 Line Integrals .......................................... 361.8 Maxwell Construction ................................... 381.9 The Best Game Strategy ............................... 42

    2. Linear Equations . ........................................ 472.1 The Quantum Oscillator ............................... 472.2 Electrical Circuits ...................................... 52

    ?~ nh::lln vp !iQn AI mI. TT r. 'I T"Io ,.. ~~"'."'1: .I. .l.l'V .V ............................... v..,.,2.5 The Hubbard Model .................................... 71

    3 Tt . ~1~ .. ~. . I . T" . n ...., .1.

    .I. & JJ) ................................... O~

    3.2 The Frenkel-Kontorova Model ........................... 933.3 Fractal Lattices ........................................ 101

    ~ AI 1\.T. _I 1\.T 1 .. n~"'."'1: .1 ~~6~& .1 ~v ~&&.~ ..L.UV

    4. Dilterentlal Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 1154.1 The Runge-Kutta Method ............................... 1154.2 The Chaotic Pendulum .................................. 1214.;1 ~tatlonary ~tates ....................................... IJU4.4 Solitons ............................................... 1364.5 Time-dependent Schrodinger Equation .................... 144

  • VIII Contents

    I!' 1\/L ~ n .1 C". _'I .L. 1~'"u. .LV,

    a.1 ltanaom 1'1umoers . ..................................... Ial5.2 Fractal Aggregates ...................................... 1635.3 Percolation ............................................ 171

    ~.,')Ji rOlymer vllaInS ........................................ 1015.5 The Ising Ferromagnet .................................. 1905.6 The Traveling Salesman Problem .......................... 200-.

    ~ . .--

    ..

    A. .rlrs't .:neps wun lY.l a.,;nemanca .................... .t;ll

    B. First Steps with C . ....................................... 225

    c. First Steps with Unix ..................................... 235

    u. FIrst ~teps wIth Xgraph'tc8 . ............................... 245

    E. Program Listings ......................................... 249

    Inaex ......................................................... ~~;j

  • Introduction

    gram which is supposed to solve the problems from the first part is described.Only the essential commands are explained so that the readers can try to com-

    x

    codes are available on the enclosed CD-ROM. In the results part, some re-sults of the computer calculations are illustrated, for the most part in the

    for each problem. The choice of these citations is, of course, subjective andno claim of completeness is made. At the end of every section, there is anexerCIse.

    over e ements 0 ,IS 0 ten use or -intensive computer simu ations.MAPLE is also a very popular tool for computer algebra. All of our pro-grams run not only on fast workstations, but also on a PC operating under

    or mux.

  • 2 Introduction

    to be defined, and the contents of the display memory have to be written tothe monitor. To do so, one has to learn complicated new languages like XII,

    generate on, hopefully, any workstation monitor elementary graphics withrelatively few commands. This package is included on the enclosed CD-ROM.

    server an compI e I. ersions 0package are included as well.

    All C programs in this book are described in the PC version. However,the figures were produced with Xgraphics. For the most part we have shownthe windows as the a ear on the monitor.

    Most C programs can be controlled interactively during their execution.The versions for the PC as well as those for the workstation allow the userto chan e some arameters or al orithms or end the am via ke board

    We want to emphasize again that our hardware and software equipmentare by no means necessary for working through the physics problems. Every

  • 1. Functions M athematicaIn

    ... _. .- ., .

    .. I'.

    nil II.l.le .................. u .lUC.l .lCVC.l U.l p.l o....... ...... ......

    , CL.l.l'y ..

    processes small packets ot on-ott data tbits) step by step. ~very packet givesinstructions to electronic switches that cause the results of elementary math-ematical operations to be written to memory and new data to be read. Thislevel ot processIng elementary InstructIOns step oy step, nowever, IS narmysuited to the formulation of more involved problems by humans.

    This is why complex algorithms should be structured. Correspondingly,high-level programming languages consist of functions or modules. In order tokeen a nrOQTam comnrehensible one should use modules that are orQ"anized~-~~ ...... +~ .c~~ A ~ ~ _ 1~ ~ _~~..:J ~4-9.1~ 99.:11 .. ~ 14-:~1~.... "'...... u'" ................ A..., ................., .... 0"'''' ..... C

    ........... "'UJ""'" ." ......................... ..

    levels of modules; this has the advantage of simplifying the modification ofsuch programs by making it more likely that only individual functions willl. n ..." 4-,.. J.,." _L -l...."" ...... u.............. .

    ......

    ... - . . . . . . . . .

    lV1 a~nemanca IS a programmIng language lug a large UIfunctions that are easily called, however, since most parameters have defaultvalues and do not necessarily have to be specified. Indeed, every command in..... ,. , , . ,.

    "

    . .. .. , t;au U~ .l COCL.l ucu CL1:l CL LUCLL I:) .y CLUUis relevant for all subsequent and sometimes even for previous commands.In this sense, Mathematica is located right at the top of the hierarchy ofprogramming languages.

    By comparison, C, Fortran, Pascal, and Basic, although they, too, are,-' .'- 1 ~ -~~ rr '~~1 and . '- . .1 1' .I ,~

    ...... .. ...... ...... ...... ...... ...... ...... ..

    (after all, Mathematica is written in C), require much more effort than Math-ematica in order to, say, generate a graph of a Bessel function in the complexnlane...

    -l -l 4-~ -l 4-~ 4-1-.~ ..~~ ~~ "Af J.J..~'T'1-.:~ ~1-.~~4-~ :~. , 4-1-. ~............,

    C ...., u'" u........ .. ................... u'" u........ ........... "'.. ....~ ...,Vl""",

    matica. vvitn simple examples, tne IOl1owing applications are aemonstratea:elliptic integrals, series expansion, Fourier transformation, X2 distributions,3D graphics, multiplication and integration of vectors, determining the zeros

    .. , . . .. . .Ul Cl.. , aIla ... Za1JIUIl.

  • 4 1. Functions in Mathematica

    In order to illustrate the difference between processing commands step bystep, a method for which we want to use the term "procedure", and call-mg a pre e ne unc ion, we wi use a simp e examp e: e m an v ue 010000 random numbers, distributed uniformly in the interval [0,1], is to bedetermined. In Mathematica, the data are generated as follows:

    In order to determine the mean value, we have to add up all these numbersand divide the sum by the number of values. We can program this step by

    Do[sum = sum + data[[i]], {i,length}];average = sum/length ]

    In this case we use functions that take advantage of the structure of Mathe-matica. The argument data is entered as a list of numbers. Apply replaces the

    Note that average appears three times: as a local variable and as thename of two functions, one of which has two arguments, the other just one.

    case.

    The reader will find an introduction to Mathematica in Appendix A; nev-ertheless, we want to point out some features of this language here: the un-derscore character in the argument data_ indicates that it can be replaced

    : = reevaluates the right-hand side each time the function is called, whereas= evaluates it only once. For example, r : - Random [] will result in a new

  • 1.1 Function versus Procedure 5

    We increase the number of array elements to be averaged from 10000 to onemillion so that we obtain run times of the order of seconds:

    #include #include

    #define LIMIT 1000000

    double average(double *,long), dataset[LIMIT];clock_t start,end;long i;

    start=clock 0 ;printf(" average = y'f\n",average(dataset,LIMIT;end=clock 0 ;

    double average( double *data,long n ){double sum=O. ;

    ong 1.;for i=O;i

  • 6 1. Functions in Mathematica

    Literature

    , ,

    Wolfram S. (1996) The Mathematica Book, 3rd ed. Wolfram Media, Cham-paign, IL, and Cambridge University Press, Cambridge

    The mathematical pendulum is a standard example in any physics course on

    Physics

    massless, rigid string of length l swings in the earth's gravitational field. LetIp(t) be the angle of displacement from the pendulum's equilibrium position

    I

    E = ; l2

  • 1.2 The Nonlinear Pendulum 7

    tcos

  • 8 1. Functions in Mathematica

    andEIIipticF[psi. k-2]

    various conventions for using them. Thus, we have K(k) =EllipticK[k-2]and correspondingly for the other elliptic integrals. According to (1.7), the

    . . . .

    l'l'yu"\lu

    T[ hiO_] = 4 EIIi ticK[Sin[ hiO/2]-2]where we have set Jf79 = 1. The command Plot draws the period as afunction of CPo:

    -)

    phinorm[x_.phiO_]:=2 ArcSin[Sin[phiO/2] sinepsi[x T[phiO]. phiO]]/phiO

    flist = TabIe[phinorm[x.phiO[i]].{i.5}]We can now draw this list using Plot, after first applyin the command

    In order to study the generation of higher harmonics with increasing non-linearity CPo, we expand cp(t) into a Fourier series. This is most easily ac-

    lish in h il _.

  • 1.2 The Nonlineax Pendulum 9

    .#. ."1': _ ... _ Al..._ rr_ _.: __ r"1': _ ... "~ .._- ...

    ..-- ' ....

    If, in (1.1), the energy E is kept constant, one obtains curves in the ( Sin [phiO/2] "'2.

    Results

    Wp h::t.vp . _1 t.hp rr of t.hp l' .1 {I)n 1 _1 i~::t. of t.hp~,,-

    .J ~1 . ~1- . .. ' . ,,- T.'~ ... ... .1- .1- .J fJ'1.J.lIJ, VJ.J. lIJ.J.V VI. lIUv ..- .I: J.5Ul.V ..............~ .... 1IJ.J.'-' ..- .L

    as a tunctlon ot tne amplltuoe CPo. It takes tne penOUlum an mfimte amountof time to come to rest at the highest apex (CPo = 7r). We can see that at first,with increasing CPo, T does not deviate greatly from the value for the harmonic

    . ~-penaumm,.1 - ~7r. vmy lOr amplltUaeS aoove ~u - 7rI ~ IS.1 slgmnCantlY

    larger. The influence of CPo on the curve cp(t) is evident in Fig. 1.2, wherethe ratio cp/CPo is plotted as a function of tIT in order to compare different

    ."'.....IVI I

    8Pi

    6Pi JT /

    4Pi ~2Pi

    ()0 Pi/4 Pi/2 3Pil4 Pi

    phiO~lg. L 1. Tne penOd 1. as a tunc-tion of the amplitude

  • 10 1. Functions in Mathematica

    I

    0.5

    -0.5

    o 0.2 0.4 0.6tff

    0.8

    Fig. 1.2. Normalized dis-placement lpnorm (t/T) of

    71",71",and 99971"/1000inside out)

    s s"

    because of the periodicity ep(t) = ep(t + T), the frequencies Ws are integermultiples of 21fIT. The discrete Fourier transformation available in Mathe-

    2 (s-1)(r-l)1fl

    6 ....,.......

    ~4......

    '"

    < 2

    0

    2 4 6 8 10 12 14

  • 1.2 The Nonlinear Pendulum 11

    such phase-space curves for different energies E. For small CPo, one obtainsa circle that becomes deformed as the energy increases. For E > m 9 l, the

    produces the following somewhat unwieldy output on the monitor:

    2 Pi + ------------- + --------------- + ---------------- +2 32 128

    2 2 2> ------------------ + ------------------- + -------------------- +

    8192 32768 524288

    P 1184041 Pi Sin[----]

    2

    P 141409225 Pi Sin[----]

    2> --------------------- + ----------------------- +

    phiO 18147744025 Pi Sin[----]

    2

    3

    phiO 202133423721 Pi Sin[----]

    2

    -3-Pi -Pi/2 o

    phi

    Pil2 Pi

  • 12 1. Functions in Mathematica

    > O[Sin[----] ]2

    2 32 128 8192

    39691rsinlO !EQ. 533611rsin12 !EQ. 1840411rsin14 !EQ.2 2 2+ ----3-2-76-8---=-+ 524288 + 2097152

    414092251rsin16 ~ 1477440251rsin18 ~+ ----5-3-68-7-0-91-2----'''- + 2147483648

    +21 11

    than 1200 ; beyond that, it increases significantly.

    ExerCIses

    1. Calculate the period T as a function of 'Po, once using EllipticK andthen with Nlntegrate. Compare the processing times and the precisionof the results.

    bo = COSct,bi+l = Vaibi ,

    - 2an

    '

    of the amplitude 'Po (-- increasing nonlinearity)? Calculate the Fouriercoefficients Ibs l/lb2 1 as functions of 'Po.

    . .

    Start:Iteration:Sto :

    from Classical Mechanics to Fractals. TELOS, Santa Clara, CAxamp es

  • 1.3 Fourier Transformations 13

    ,

    Zimmerman R.L., Olness F.I., Wolpert D. (1995) Mathematica for Physics.Addison-Wesley, Reading, MA

    1.3 Fourier Transformations

    his or her disposal: the decomposition of the signal into a sum of harmonicoscillations. This tool, which has been thoroughly investigated mathemati-

    most any signal, even a discontinuous one, can be represented as the limit ofa sum of continuous oscillations. An important application of Fourier trans-

    unc Ion III erms 0 simp e OSCI a Ions pays a Ig ro e no on y III P ySICS,but also in image processing, signal transmission, electronics, and many otherareas.

    Frequently, data are only available at discrete points in time or space.In this case the numerical al orithms for the Fourier transformation areparticularly fast. Because of this advantage, we want to investigate the Fouriertransformation of discrete data here. In the following sections we will use it tosmooth data to calculate electrical circuits and to anal ze lattice vibrations.

    Mathematics

    Let ar , r = 1, ... , N be a sequence of complex numbers. Its Fourier transformIS e sequence s, 8 = , ... ,

    N_ 1 '" b 2 . (r - 1) (8 - 1)

    ar - -- L..J s exp - 1I"1-'-----'----'---~s=1

    (1.8)

    (1.9)

    Thus, the signal {ai, ... , aN } has been decomposed into a sum of oscillationsbs

    c r =--

    s- s- s s

    of an amplitude and a phase. Both (1.8) and (1.9) can be extended to all

  • 14 1. Functions in Mathematica

    perlo

    (1.11)

    symmetry:

    1 ~ . (r - 1) (-8 + 2 - 1)= -- LJ ar exp 27fl N

    (1.12)

    A useful property of Fourier transforms becomes evident in the convo-lution of two sequences {/r} and {gr}. In this operation, the elements Ir

    . . . .

    Let the sequences {hs}, {gs}, and {fs} be the corresponding Fourier trans-forms. Combining the Fourier expansions

    . (m - 1) (j - 1)N

    1 N_Ir+l-j = N Lin exp 2 . (n - 1) (r - j)- 7fl....:.....---:.....-'------.;....;...N

  • 1.3 Fourier Transformations 15I 1 '\ 3

    h. - I --.::..- \ '\' n. I.\yN} L...J " .r,j,m,n

    . (r - 1) (s - 1) - (m - 1) (j - 1) - (n - 1) (r - j)xexp 2~1 AT .

    .1.1'

    The sums over rand j can be evaluated

    ~ Avn (?'7I"l lq.) - 1\T Ji. ... lo t=. '71.

    L.J -r \ NJ . .,,"" ,t:....:l

    and we are left with

    hs = VN L iJmin exp (2~im 1\T ~) 8s- n,o 8n- m,o = VNiJsis . (1.14)m,n ,

    . /

    Thus, after the transformation, the convolution turns into a simple product.The inverse transformation then yields the convoluted function

    l:!... (". l' (r: nhr ) fl.'l Is exp 2~i ' -, , " (1.15).~ lVs=l

    In the next section, we will use the convolution to smooth experimental data.

    Algorithm

    In Mathematica, one obtains a list of the Fourier coefficients {b1 , .. , bN}via tne cornmana

    "'our~er ltal, .. , al'UJ

    and their inverse by usingInverseFourier[{bl, ... , bN}]

    It may be interesting anyway to look into the Fast Fourier 'I'ransform (FFT)algorithm. The most straightforward way of calculating all series elements bsaccoraing to ~ l.lSJ amounts to mUltlplymg a matrIX OJ tne IOrm

    ~ , ~, , .

    Ws,r (N) = IN exp 2 . ~1' .1) ~~ .1)~l Nbv a vector a - (a, .. aJ\T) this takes N2 stens. The FFT allrorithm how-"''O.'''...........~ .1 ,1. +l.", ............. '" ;~ .... ..,. ........ l."'... ,..~ "'+"'Y"'" +h .... + .1 __ ~~'V 'V~, 'V..-&

    &U&&'V ......-~&'V &&~ .... ""~ .... u'V,t'.... U&&.... u --- _- -- ...,.......1 .....,

    N log N. To this end, the sum (1.8) is split up into two partial sums withodd and even indices r:

  • 16 1. Functions in Mathematica

    t=l t=l

    1

    +exp

    V2Here, b~(N/2) and b:(N/2) are the Fourier transforms of the coefficients

    F(N)=2F(~)+kN. (1.17)

    Application

    J(t) = ~ [sign (r + t) + sign (r - t)] (1.18)

  • 1.3 Fourie:r; Transformations 17

    n=-oo

    where w = 271"IT and the In are determined by integrals over f(t)T/2

    f (t) exp (-inwt) dt .

    this inte ral is easil executed the result is

    (1.20)

    (1.21)

    bs _ [. (N - 2) (s - 1)]v'N - exp 1 71" N00

    L fI-s+kN.k=-oo

    (1.22)

    00

    L fI-s+kNk=-oo

    (1.23)

    n 's - " ...,.

    The question whether Ibsl/v'N < Ill-si or Ibsl/v'N > Iit-sl, the effect ofthe so-called al~asing, cannot be a~swered in general. This depends on the

    frequencies corresponding to N/2 < s < N. In (1.11) in the mathematics

  • 18 1. Functions in Mathematica

    0.2 .,,

    0.15 \

    0.1\

    \\/ \ ~ --v VV~0'-- .......... --... ....... ........__--'-----'

    5 10 15 20 25 30

    Fig. 1.5. Continuous and discrete Fourier transformations of a rectangular pulse.The solid curve shows 111-8 I as a function of s, the filled circles are the values ofIbs IN-1/ 2

    1.25 I I.

    10.8

    0.750.5 0.6

    0.25 0.4

    0 0.2

    -0.25 0-0.5

    -.. -~ v ~ .. -..

    AO _._. - J~~ ._-- ~ \ ~J-' - - ~ \ 0;"00'inverse Fourier transformation to continuous t values

    IV . V

    .... AA IAAA V"-~ v ~ ..

    . ro.f 4-l. .... "-- ---

    . .. . .part aoove, we nave snown tnat tne sum can oe taKen over any InterVal orlength N. We take advantage of this freedom to choose an interval that issymmetric to the origin and use only the lowest frequencies:

    N/2~ t. \J \"rj

    1 ~ I. '" ~r - 1) ~S - 1)

    V'" s=-N/2+1

    1 N/2= r:-; ~ bs exp

    V lV s-I2 . (r - 1) (s - 1)

    - 1rI 1\1.l.Y

    1 ~ b [ 2 . (r - 1) (Sf - N /2 - 1)]+ ..;N LJ s'-N/2 exp - 11"1 N

    s'-1I\T J?

    1 ~ ...;N~ Ds exp .~1I"1

    r-1)(s-l)N

  • 1.3 Fourier Transformations 19

    *N/2-s'+2

    1. Peak voltage. A time-dependent voltage is probed at N = 64 pointsin time resulting in the values U1 , , UN. Assume that its Fourier

    random 'Ps. What does the signal look like now?(c) Competition: The objective is to find phases that result in the

    low st ssi I Ii..{cp .. } r

    2. Aperiodic crystal. Assume a chain of atoms with a periodic arrange-ment.

    ficients Ibsl of the function ar that is defined as1 if atom 1 is at the position r ,

    ot erWlse.

    (a) Plot the Fourier spectrum bs .(b) Next, generate a random sequence of Is and Os and plot its Fourier

    (i) Start with: 0

    (ii) Generate the next line by appending the next-to-Iast line to thelast one.

  • 20 1. Functions in Mathematica

    Crandall R.E. (1991) Mathematica for the Sciences. Addison-Wesley, Red-wood City, CA

    Press, Cambridge, New YorkDeVries P.L. (1994) A First Course in Computational Physics. Wiley, New

    am-

    Experimental data are usually affected by a noticeable statistical error. The

    YSICS

    Let f(t) be a physical quantity that is measured at discrete times ti. The

    9i = Ii + Ti , i = 1,2,3, ... , N . (1.24)

    into account the neighbors according to their distance Ii - i I from the pointi. Very distant neighbors are only weighted weakly. As a weight function, or

  • 1.4 Smoothing of Data 21

    j=1

    Then 9r is constructed as follows:N

    9r = L9r-j+1 k j .j=1

    (1.26)

    N.(8 - 1) (r - 1)

    N

    where 9 and k are the Fourier transforms of 9 and k respectively.

    We generate the data we want to smooth as an array data in Mathematica,using the values of the Bessel function J1 (x), and add noise in the form of

    data=Table[N[BesselJ[l,x] + 0.2 (Random[]-1/2)], {x, 0, 10, 10/255}]

    u:

    This, however, puts the largest functional values in the middle of the array

    the command

    kernel = RotateLeft[kernel,127]

    kernel = kernel/Apply[Plus, kernel]

    Sqrt[256] InverseFourier[Fourier[data] Fourier[kernel]]

  • 22 1. Functions in Mathematica

    Figure 1.7 shows the results of the calculations done with u = 0.4. Thesmoothed data are compared to the noisy data and to the original function.

    curve" is used for the kernel. In the third edition these mistakes have beencorrected. Finally, we want to point out that one has to be careful when doing

    . . . .. .

    mials through adjacent interpolation nodes and require their curvatures tobe minimal. We cannot treat this broad area of statistical data analysis here;

  • 1.5 Nonlinear Fit 23

    The result of the algorithm for smoothing data introduced above depends onthe width u chosen for the kernel. Calculate the smoothed data for a wide

    Press W.H., Teukolsky S.A., Vetterling W.T., Flannery B.P. (1992) Numer-

    , ,

    Wolfram S. (1996) The Mathematica Book, 3rd ed. Wolfram Media, Cham-paign, IL, and Cambridge University Press, Cambridge

    1.5 Nonlinear Fit

    ,

    frequently fitted to the data. The models are - hopefully - the results oftheories; the computer is needed to find the "best" parameter values and

    ,

    be able to specify a measure for the precision of the parameters.Using the example of a damped oscillation that is measured at just eleven

    Theor

    z, z , , z

    unknown M -component parameter vector a is to be fitted. Assume further

  • 24 1. Functions in Mathematica

    vams w en average over many expenmen s an ave e vanances ui' I.e.,(ci) = 0 and (cn = u;. The "best" set of parameters ais defined to be thevector ao whose components minimize the quadratic deviation X2 , where X2IS e ne as 0 ows:

    (1.28)

    2o

    PN - M (X~) = r () /o

    t N-M 1e- t-2-- dt. (1.29)

    ,

    the possibility that our experiment belongs to those 1% of all cases for whichX2 is greater than or equal to X5. If, however, we had P = 0.9999, our fit

    x2 (a) has a minimum for some parameters ao and the value of x2 (ao) fallswithin our confidence interval. If we could repeat the experiment several

    wan

  • 1.5 Nonlinear Fit 25

    aI, a2, ... . From the width of the distribution of each component of the akwe obtain the error bars for the fit parameters ao.

    ,

    it can be shown that the quantity L1 = X2 (a) - X2 (ao) is again distributedaccording to the distribution function P from (1.29), this time with M rather

    (1.30)determines the re ion of allowed values of a. In arameter s ace the re ionsof constant L1 are ellipsoids. The projection of this (M - I)-dimensional sur-face onto the axis i then yields the error interval for the parameter ai.

    m

    For the nonlinear fit, too, it is easiest to use the functions available in Mathe-matica. To find the minimum of x2 (a), we use the function NonlinearRegressrom t e pac e Statistics'NonlinearFit'. t 0 ers vanous POSS1 Illes

    for entering data and initial conditions; in addition, one can change themethod of the minimum search and have the program display intermedi-ate results. Of course, one can also provide one's own definition of x2 (a) and

    oscillation

    f[t_] := a Sin[om t + phi] Exp[-b t]

    with four parameters a = {a, om, phi, b}. This oscillation is measured at11 points in time ti for the parameter set a ={1, 1 ,0,0. 1}, and noise in theform of uniformly distributed random numbers is added to the data:

    om ,{t, 0, 3Pi, 0.3Pi}]

  • 26 1. Functions in Mathematica

    0.2

    / 2 2x dx = 150 .e searc or a mInImUm IS aClltate 1 we can provi e an approximate set

    of values for ao. After loading the statistics packages needed viaNeeds "Statistics" Master" "

    NonlinearRegress[data.f[t].t.{{a.1.1}.{om.1.1}.{phi . 1}.{b . 2}}.

    sity distribution, i.e., the integrand of P7(X5), (1.29), whereas CDF yields theintegral, i.e., P7 (X5) itself. With Quantile, the function P7 (X5) is inverted.

    Quantile[ChiSquareDistribution[7]. 0.95]

    the area in parameter space for which x2 (a) = x2 (ao) + .::1.

    Figure 1.8 shows the function f [t] for a=i, om=i, phi=O, and b=O .i, as wellas the 11 data points that were obtained from f [t] with the random errors

    The X2 distribution is shown in Fig. 1.9. Strictly speaking, the distribution(1.29) is valid only for Gaussian-distributed errors Ci, but we do not expecta large difference for our uniformly distributed errors Ci. For the correct set

    , . ., z

    We obtain the confidence interval for the value of X~ from

  • t1.5 Nonlinear Fit 27

    Fig. 1.8. Damped oscilla-tion and noisy data

    o 5 10

    chi2

    15 20 Fig. 1.9. X density dis-tribution with seven de-grees of freedom

    and the result of {limit [0.05] , limit[0.95]} is {2.2,14.1}. This means

  • 28 1. Functions in Mathematica0.2

    0.14/)J0.15 0.12 -0.1 / '\~V.I // // OOR

    ..,;) 11/ *l I0.05 0.06 ~ ~J0.040 f L..-// ............ ..-/'-l/ v.v..:.

    00.4 0.6 0.8 I 1.2 0.9 0.92 0.94 0.96 0.98 I 1.02 1.04

    a om

    'INa 1 111 n nf ,,2(.n) T UTifh fho ..._h ....1"' .... 0 i ....'CO "" , -~ r ..

    space (left) and with the om-b plane (right)

    If one vanes the frequency om rather than the amplitude a the compen-,.

    .1 ~hrn,p rlnp~ nnt 1 ~~ .1 in thp riCTht_h~nrl 1 nf'rr '0' ..

    Fig. 1.10. The true values, om=1 and b=O .1, lie close to the edge of the innerconfidence region; therefore, the confidence interval should not be too nar-row If onp nlot.~ f rt:1 for two v~ll1p~ frmn F'i IT 1 10 ,1. ;:1..:1 ~

    ..J"., .,., .1.. ..... 1..

    J

    ...."" ~ ... "" ........"" D,' Ll. '11..... v .L~ a..uu CLv.~, ..... 'v, v.uoc; ~a.u ooc;oc; .L.U .I.' .LE) .1. .1..1. lIua.lI UVlIU ~U.L voc;o OllU.l .loc;p-

    resent the data relatively well. The small number of data (N = 11) and thelarge error do not permit a better fit.

    A -'I' -'I 4-1. 4- 1. .1. 1 ,,. 1 ..< ...0 ~.... u ..~'" u ...."'v.. J , u ..~"'.. '" ~o LW." V'" J.VJ.

    estImatmg the errors OI the parameters. une taKes the optImum parameterset ao for one experiment and uses it to generate new, artificial data thatare fitted in turn. Repeating this for the same ao yields a set of parametervectors ak. Figure 1.12 shows the results of 100 iterations, using the ao from(1.31). together with the contours from Fig. 1.10. It can be seen that in the(a,b) projection even more than 90% of the data fall within the outer contour

    I /""'\.'" ,., .. l \V.1J H0.5 A';:;' 0.25

    ..... V ~ 4 ,.~v V-0.25-0.5 Fig. 1.11. Two fit curves, ~-

    ..........." J.,J.VJ."" r -~I'

    0 2 4 6 8 lIt:u, UV.lll lI.l.lt: VUlIt:l' ~Vll-liour OI line a-D plOli snownt in Fig. 1.10

  • 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2

    1.5 Nonlinear Fit 29

    Fig. 1.12. Parameter values a andb from the fits of the artificial data

    0, ,

    take into account only the first 68 of these vectors, the last of which sets a X2limit X~8 = x2 (a68)' All these remaining ak then lie inside the quasi-ellipsoid22'

    o am e ex reme ImenslOns 0 e e IPSOl . n IS way, we can even ua ymake the statement that with 68% certainty the true vector atrue lies in aquasi-ellipsoid that is contained in the rectangular parallelepiped

    Of course, not every point a of the rectangular parallelepiped belongs to the68% region, owing to the correlations mentioned above. Whether or not itbelon s to this re ion can be determined from its 2 a .

    Exercise

    +a exp

    data = tvinpeak.dat

    fit parameters.

  • 30 1. Functions in Mathematica

    Bevington P.R., Robinson D.K. (1992) Data Reduction and Error Analysisfor the Physical Sciences. McGraw-Hill, New York

    , "

    Press W.H., Teukolsky S.A., Vetterling W.T., Flannery B.P. (1992) Numer-ical Recipes in C: The Art of Scientific Computing. Cambridge University

    am-

    The expansion of physics equations in terms of a small quantity is an impor-

    exact potential.

    ysics

    The electrostatic potential4>(r) of N pointlike charges ei at the positions r(i)is given by

    N

    The electric field is determined by the gradient of 4>:

    OX' oy' ozWhen observing this potential from a long distance, Le., for Ir - r(i) I~ 00,

    4>(r) = - + - + -rQr+Or r3 2r5 (1.34)

  • 1.6 Multipole Expansion 31

    Nq = ei, P = eir (i), Qkl =

    i=l i=l

    where rii ) is the kth component of r( i) .

    N

    We want to investigate this expansion using an example of five positive andfive negative unit charges that we place in the x-y plane, randomly dis-

    rpoint:={2 Random[]-1, 2 Random[]-1, O}Do[r[i] = rpoint, {i,10}]

    Drop[r[i+5],-1]+{O.08,O}}].{i,5}]]

    =

    p1 = Graphics[Table[Line[{Drop[r[i],-1]-{O.08,O},Drop[r[i].-1]+{O.08.0}}],{i.5}]]

    . .

    Next, we use Circle [ ] to draw a circle around each symbol,

    o tions] to lot all four ra hies ob-

    two vectors,

    The dot between two arrays of numbers - Mathematica's extended notationfor this is Dot [11,12] - effects a scalar product of the two vectors, i.e., thesum of the products of corresponding components of the vectors. Without thedot on the other hand the vectors would be multi lied element b element

    ei = 1 and:

  • 32 1. Functions in Mathematica

    ...

    1 c:..~

    1 $0.5 Ss

    ""

    >. 0 a:"'.....'J7 EIb S'V'J ~

    -0.5-1 $

    -1.5....

    -...,

    -1 -0.5 0 0.5 1 1.5 2-2 -1.5 Fig. 1.13. Positive and negative chargesx randomly distributed in the x-y plane

    pot [rh_] := Sum[1/dist[rh.r[i]]-1/dist[rh.r[i+5]].{i.5}]We present three ways to visualize this result: first we use Plot3D to plot the

    .1 ,'I.. r. r .11 ..1 . . r .'1.. 1r ,U.l lJ.l.l{;; .lV.l.l.l.l V.l " ............J'" (ld..lU ~ VUlJ V.l lJ.l.l{;; "'" -Y A ,next, we plot the contours 01 thiS mountaIn range lJy usmg (;ontourPlot;finally, we calculate the electric field and plot it via PlotVectorField, fromthe package Graphics" PlotField'. In order to see anything in the lattercase, however, one has to normalize the field, i.e., display only its direction.

    The dinole and auadrunole moments can be formulated lust as easilv inMathematica. According to (1.35), we have

    dipole = Sum[r[i] - r[i+5].{i.5}]. .,_r_, ._

    ....... :.... r~-- ..r r,~"

    . r r .. " T~ r" __" ,.., r,o .... r ...... ,'L'" ... L L .....J .J ... L L ... .J .J ...... L .... ' ' ............ v.J.~.........I.~........I.J

    _.. ~ ......... ~ .. ... _.... r. _, ..q~wn

    .. -~ i LLL~JJ - ~ -~ 'LL'L~"OJJ ,"l~,OfJ

    Here, the Kronecker symbol 8kl is represented by the following expression:~. .~

    .LI LK==.L .L UJ

    To calculate the magnitude of a vector r, which we could also express asdist [r ,0], we use the function

    ma~n[r ]=Sart[r.r]

    With this, the expansion (1.34) of the potential 4>(r) can be defined immedi-ately. In our example, there is no net charge (q = 0); therefore, the first termpot 1 is the dipole term, and pot2 contains the quadrupole term in addition:

    po'Cllr_J - Q1p0.1e.r I magnlrJ,jpot2[r_] = pot1[r]+1/2/magn[r]A5 r.qsum.r

    Here, qsum is an array of arrays, in this case a 3 x 3 matrix; r is an arrayof n11Tn hPTQ 1 P :l. 'T'hp r_ nof: r 1 ..1" ...'I hv :l. rlot (.,

    .1 ".r

    oJ, .~r. , . " .'1.. , .

    .lV.l l.J.l{;;V.llJ'y, V.l ,0 vv .llJ.l~ a..l.l a..l'.1 V.l

    indices (= nested arrays). Therefore, in this case the quadratic form "vector

  • 1.6 Multipole Expansion 33

    conventIOn programmmgnest two for loops:

    for(j=O; j

  • 34 1. Functions in Mathematica

    -2L.o.....__---'-__--....~ ._J Fig. 1.15. The same potential as in-2 -1 0 1 2 Fi. 1.14 but dis la ed as a contour lot

    Fig. 1.16. The exact po-tential (solid curve), thedipole term (shorf-dashed

    not correctly represent the two positive maxima near the positive charges.Even with the quadrupole correction (long-dashed curve) the approximation

    .

    Exercise

    enerated by a current I flowin

    vector potential A, from which the magnetic field B = V x A is calculated,

  • 1.6 Multipole Expansion 35

    _ - 1// / / I. 1 \ ~ ~ '\ " " "," ---_ ----//////Il \ \ \ \ ",,,,,, --

    ... ---//// / //Il \ \ \ \ '\ """"'"----//////1111 ~\\\\'\'"''''''-10

    11)v

    11)

    Fig. 1.17. The directionof the electric field of theten unit charges in the

    n

    takes a particularly simple form in spherical coordinates (r, 0, t/J), with unitvectors er , e(J, et/J. Only its t/J component is non-zero, and for this component

    or..... or

    Lilt: uy J.U. glvt:~ Lilt:

    At/J (r 0) = fLo I a [(2 - k2 ) K (k) - 2E (k)], 1(" Ja2 + r 2 + 2arsinO k2

    ,y .........

    k2 = 4ar sinO .a2 + r 2 + 2arsinO

    K(k) Rllinr,icKrk-21 and E(k) Rllin'HrJ;'rk-21 are the .1 ..... 'V.. u ....'V ...... uu ........... 0... ........

    Calculate the magnetic field B(x, y, z) and plot its direction in the x-zplane, using the function PlotVectorField[. .. ]. Attempt to plot the field1:~" ........~ D :~ 4-\.. ..... ~ _.1 \.... ~ .....:4-~\..ln no 1

    nint ~applies omy to Mamematica versions oeIOre .l.U): ~ne prOOlem tnatMathematica does not know how to calculate the derivatives EllipticK J andEllipticEJ can be solved since the derivatives of the elliptic integrals canbe expressed again by elliptic integrals. The two lines

    . . - - . . - - . .--

  • 36 1. Functions in Mathematica

    Gradshteyn I.S., Ryzhik I.M. (1994) Table of Integrals, Series, and Products.Academic Press, Boston, MA

    ml ., ac manAddison-Wesley, Reading, MA

    Wickham-Jones T. (1994) Mathematica Graphics: Techniques & Applica-

    1.7 Line Integrals

    Work = force x path length. This seemingly simple equation from high school.. ...

    p t;

    F= -vp. (1.37)

    Algorithm and Result

    s in space r

    Sin[2Pi t] t}

  • 1.7 Line Integrals 37

    z

    The first path is a spiral, the second the straight line connecting the twopoints, and the third a semicircle in the x-z plane. ParametricPlot3D dis-

    int[r_]:=Integrate[k[r].v[r].{t.O.l}]

    cur

    o O}.

  • 38 1. Functions in Mathematica

    r 1

    o o

    where we choose s (t) = r4 = t {x, y , z} as a path from 0 to r. Except forthe si n int [r4] ields the otential ~ x z = - x + xz

    We can now slightly modify the field F(r), for example tof[{x,y,z}] = {2x yA 2 + z A 3, xA 3, 3x z A 3}

    ,

    now calculate the curl again, then curl [f [ {x,y , z}]] yields a value differentfrom 0, in agreement with the dependence of the integral on the integration

    Exercises

    , , ,

    three line integrals and plot the absolute values of the three accelerationsId2r/dt21 as functions of T.

    . .

    Literature

    cations, Mineola, NY

    Frequently in physics the mutual dependence of quantities is governed bynonlinear equations that can only be solved numerically. One example of thisis t e curve 0 a van er a s as wit t e tern erature as aparameter, which obtains physical significance through the so-called Maxwellconstruction.

    At low temperatures, the isotherms of the equation of state, which is

    ,

    to be replaced by horizontal lines that in a sense bisect the loops. In order

  • 1.8 Maxwell Construction 39

    non inear equa ion a, ur ermore, con ains an in egr . n is way, oneobtains a description of the phase transition from gas to liquid.

    For an ideal gas of N noninteracting classical particles with no internal de-rees of freedom the theor of heat rovides a sim Ie relationshi between

    pV = NkBT. (1.39)Here, kB is the Boltzmann constant. Taking into account the interaction

    (p + ;2) (V - b) = NkBT (1.40),

    function of the volume V for constant temperatures T. For high temperatures,the pressure decreases as the volume increases, whereas for low temperatures

    Sa aTc = 27NkBb' ~ = 3b, Pc = 27b2

    (1.41)

    (1.42)

    (Ii + :2) (3V - 1) = 81' . (1.43), ,

    i.e., over a certain range three volumes Vi, V2, and V3 correspond to eachpressure p. Fo~ thermodynamic reasons, the transition_ from the gas, with a

  • 40 l. Functions in M athematica

    Vftr

    - -1- - \J p( V)d V =Pt ~V3 - VI) . (1.44)

    VI. .. .. . . .

    ".. . T-P . .

    ~lJ Pt,_ga:s ~IlU nqulU are ly .. lur au v V WllJnVI < V < V3; one observes a two-phase mixture. Geometrically, the equa-tion above means that the ar~a bet~een the curve p(V) and the straight linePt = con~tant in_the range Vi to V2 is the same as the corresponding areabetween V2 and V3 (see J:4'i~. 1.19). Usm~ Mathematzca, we want to construct+h~ ii. +_h~4o ,~ .l., ... ",,,,,, linp

    ..- ~ ..-

    Algorithm and Result

    t'Irst, we venty l1.4~) tor tne cntiCal pomt. we enter tne van aer WaalSequation (1.40) (NkBT = t):

    n=t:/(v-h) - ;t/v-?..

    .......A ' ,.. lo 'h.n lo.nn (1 111\.~....~ ~....~ ~

    .. \ '/

    eq1=D[p,v]==Qeq2=D[p,{v,2}]==Q

    TT , , , ,. , , ,.nel-e, LIlt: OJJ ...... ..,,,.. au

    ~,w Lel:iLl:i Lue

    .."'

    and is executed first. We solve these equations for t and v:

    sol=Solve[{eq1,eq2},{t,v}]which results in a rule:

    8 a{{ t -> ----, v -> 3b}}

    ?7 h

    Since the solution is not always unique, Solve yields a list of rules; hence thedouble curly braces. We obtain the critical pressure by applying the innerDart of the rule to D,

    oc = oj .sol[[1]]with the result a/ (27 b-2).

    Now we define the normalized function p(V) from (1.43):.. .,

    .... J, .... .., .... J _ ....}lLV_J - 0'" ,,,,,v -~I -"", v 10

    For the two-phase line we need two equations in order to determine the twounknown volumes vi and v3 between which gas and liquid coexist. The first

    ""',," t'h",t ,~.

    an" '"Ht" nf.. -J "'1 .. ~ r

    eq3=p[v1]==p[v3]

  • 1.8 Maxwell Construction 41

    '1"'1-.~ .J ~~~ .. 1-.~ ..~.~ ~_~~~ .. ..~ {1 AA\ .&. ........ ""........ .. v........ v ""................... .............."".............0 V"" \.L .....J

    eq4=p[vl]*(v3-vl)==Integrate[p[v].{v,vl.v3}]An attempt with Solve indicates that Mathematica does not find an analyticsolutIOn. '1'heretore, we wil1 use FindRoot to obtam a numencal solutIOn. '1'0find a reasonable result, however, the initial values of the (vi, v3) search haveto be specified rather precisely. Therefore, for temperatures T < 1 the functionplot [T_J first determines those values of v where p [v] attains its local min-

    and . . and ~ 1 thp. .-t. . of thp.V~IV..

    .. ... '1"'1. .. I. ~ lIr il. i'.J '" ., r. r ..' r ..... ., .,

    V"''''', V" ....... " .L ............. v ......... ....v~V .... L'p LV.I -.PLV"....... ".I ,V.I .. ,,-

    turns three solutions; the two outer ones are suitable initial values. The finalMaxwell function then is

    "Dmax[v J:= If[v < vi II v > v3. "D[V]. "D[v1]J

    Thus, if v is between the solutions vi and v3, the two-phase line is returned,otherwise it is p[v]. Fig~re 1.19 shows the result for various values of thenormalized temperature T, together with the unphysical functions 'P [v]. As'IT _~ 1 /1. tho ' . 'T'ho tnn iho'l '1"1(17\ in tho CT~'l

    .,.... .....

    ..... r, I O'phase, and the next lower one represents the situation just at the criticaltemperature. The three lowest curves show the separation into a liquid (small

    ,

    .) ~mrl ~. .1- A)onu t.hp ..~.~ .1- linp 1" '.J ~.nrl U~R ...... .. ..... .. .. .....

    ,. ..., .J.J.J. ~"i'

    2

    --1. IJ

    1.5 \1 ')l\\ ~

    c.. 1 \~-~0.75\/ ~......-.-..f\,--

    /~.~

    \/0.250

    1 1. j 4 )

    V

    "":... .. .. 0 l\Jf .. ~~_ ..1-." u ....~ ..:1,,_ "'X7........ 1... T...~.. - ~~_ ..1-."0 _e -- ..~.. v ....~ ~.... ~~.. -~ ~'1' ..~.. v ....~

    ,. , ,;:, ~ ~~ . ~ ~ ~~ ~~" ~ ~~ , , ,-s.- oL .L .vtJ, .L .v, v.~tJ, v'~"', V.otJ \ "up loU -,

  • 42 1. Functions in Mathematica

    Consider a quantum particle of mass m in a one-dimensional potential wellfor - a

  • 1.9 The Best Game Strategy 43

    , . .,

    o 1 3 1K = -1 10 4 2

    7 -2 3 7

    Since the gain of R is the loss of C and vice versa, this game is called thetwo-person zero-sum game. This procedure is repeated many times. At the

    C, on the other hand, of course wants to minimize his losses, so he looksfor the minimum of K. Thus, for each choice i made by R, he looks for

    up WI e I ea 0 c oose e co umn a Yle s e sma es oss m eworst case. For each choice j, C would lose at worst the amount maxi Kij.Therefore, he chooses that value of j which corresponds to minj maxi Kij,in this case column j = 3. Using similar reasoning, R would choose the rowassociated with the value max min K i.e. i = 1. With this strate theamount K l3 = 3 would be paid to player R after each move. The limits eachplayer aims for have different values:

    Now what does a gain of 3 mean to player R, who, with this strategy, mayexpect a minimum "gain" of O? And should player C, who would have had tocount on a loss of 4 in the worst case, be satisfied with 3? Indeed, player R hasever reason to rethink his strate as closer ins ection of the a out tablereveals that, if he randomly chooses rows 2 and 3 with the same frequency,his gain will be at least 3 for any choice made by C. And if he slightly prefersrow 3 in the rocess he will even exceed the ain of 3. One can see from this

    jthe three frequencies PI, 112, and P3 (with PI + P2 + P3 - 1), according towhich he chooses the rows without any correlation. On average, he receives

    K = 2: Pi qj K ij .i,j

    (1.46)

  • 44 1. Functions in Mathematica

    Correspondingly, C looks for a strategy qY ... q~ that yields the valuemm max

    Contrary to the deterministic game (1.45), the optimal stochastic strategies

    This is the famous Minimax theorem, which J. von Neumann proved in 1926,at the a e of 23. We want to ut the meanin of 1.49 in words: if la er Rchooses an optimal strategy p~, ,pg, then his gain after very many movesis at least Ko for any strategy ql, , q4 of player C. This means that for anychoice 4 with i > 0 and 1 + 2 + 3 + 4 = 1 we have

    i,jFrom this inequality, one can derive a system of four conditions, since with

    o

    LP?Kij > K o for all j .

    If we assume that ~ > 0 then with x

    l:X?Kij > 1 for all j .i

    . K 0 this becomes

    (1.51)

    (1.52)

    Xl,X2,X3 WI Xi _ , e 1mstrategy Po = Koxo and the associated average gain K o are determined by aminimum of c . x with the added condition KTx > b, where the latter vector

    C, since with qo = Koyo one obtains

  • 1.9 The Best Game Strategy 45

    Then, analogously to (1.50) and (1.51), for any strategy P of R:o .

    i,i

    This means that in the worst case player C, using an optimal strategy, will

    The minimum of a linear function c . x with the added conditions KTx > band x > 0 can easily be determined using Mathematica. For our example we

    c = {1, 1, 1}b = {1, 1, 1, 1}k = {{o, 1, 3, 1},{-1, 10, 4, 2},{7, -2, 3, 7}}

    and

    LinearProgramming[c,Transpose[k],b]

    Instead of searching for the maximum of b . y we can search for theminimum of -b . y just as well. The inequality Ky < c is equivalent to

    This yields the vector Yo and consequently Ko = 1/(b Yo) and qo = KoyoFor our exam Ie the calculation ives the results

    Po =

    This means that R uses an optimal strategy if he chooses rows 2 and 3

  • 46 1. Functions in Mathematica

    this matrix. For each move, the player chooses one of the four rows; at thesame ti~e, the computer selects one of the columns with the ~robabilit.iesqJ.

    notice, however, that the computer wins in the long run, unless its opponentcalculates the best strategy p~ and acts accordingly. At the end of the game

    Exercise

    n extend the well-known arne of chance with the three s mbolsrock, paper, scissors to the four symbols rock, paper, scissors, and well. Inthis version, two players each pick one of these four options and win or loseone oint accordin to the followin rules:

    s iss rs. Paper covers well, paper wraps rock. Scissors cut paper. Rock smashes scissors.

    Formulate a payout table for this game and use it to calculate the optimalstrategy for both players.

    von Neumann J. (1928) Zur Theorie der Gesellschaftsspiele. Ann. Math.100:295 [English transl.: Bargmann S. (1959) On the Theory of Games of

  • 2. Linear Equations

    (with the exception of the Hofstadter butterfly) in such a way that they canbe examined using predefined functions. When we deal with the electric cir-

    2.1 The Quantum OscillatorThe e uation of motion of uantum mechanics the Schrodin er e uationis linear: Every superposition of solutions is itself a solution. Therefore, themethod of separating the equation into a space- and a time-dependent partb a roduct ansatz and later su er osin these roduct solutions is success-

    ,

    of a linear differential equation. The solutions of this equation are wave func-tions !P(r), which assign a complex number to every point r. More specifically,

  • 48 2. Linear Equations

    Physics

    ,

    in the quadratic potential V(q) = mw2q2/2. Here, q is the spatial coordinateof the particle. In dimensionless form, the Hamiltonian of the system is

    Here, the energies are measured in units of liw, momenta in units of ../limw,and lengths in units of JIi/(mw). The eigenstates Ii) of Ho can be found in

    . ..

    'Pj (q) = (2 ji!0f") - e -q 21lj(q) ,where 1lj(q) are the Hermite polynomials. We have

    0_'J

    The c~ are the energies of the eigenstates of Ho, and the matrix (iIHolk) isdiagonal because the eigenvalues are not degenerate.

    . .

    H = Ho+ Aq , (2.3)and try to determine the matrix UIHlk). To do this, it is useful to write q as

    . . t

    v'2where a and at have the following properties:

    a J =

    a 10) = 0 and a Ii) = VI Ii - 1) for i > 0 . (2.5)Consequently, the matrix representation of q in the space of the unperturbed

    = ~Vk + 15j ,k+l +~Vk5j ,k-1 = ~Jj + k + 15!k-jl,1 ' (2.6)The a roximation that we will now use consists 0 de nin this in nite-dimensional matrix for i, k = 0,1, ... ,n - 1 only. The Hamiltonian H =Ho + Aq4, or more precisely its matrix representation, is to be approximatedb an n x n matrix as well, where Ho is re resented b the dia onal matrix

    eigenvalues of H for different values of n.

  • 2.1 The Quantum Oscillator 49

    The construct Ihs : = rhs /; test means that the definition is to be used

    q[n_]:= Table[q[j,k], {j,O,n-l}, {k,O,n-l}]and according to (2.2) Ho is calculated as

    With this, H can be written as

    Results

    The call

    o3

    o

    / MatrixForm ields the Hamiltonian matrix

    1. + 15 ).2 4

    (2.7)

    Its eigenvalues are

    discrepancies from the exact result.

  • 50 2. Linear Equations

    ~Q ~8 ~7>.6~5 ~~~ 4~3

    2---

    Fig. 2.1. Approximate val-.. ,.. '"

    1 ut:::i lUl' Lllt: luur t:ll-ergy eigenvalues 01 tne quan-

    0 0.2 0.4 0.6 0.8 1 tum osCillator with the an-harmonicity Aq4, as a func-

    lambda tion of A

    How accurate is the approximation? This can be seen in Fig. 2.2 forthe example of the ground state energy co. For an anharmonicity parameterA = 0.1, co is plotted as a function of lIn, for n = 7, ... ,20. Obviously thisfunction is not monotonic. Althoue:h we do not know its asvmntotic behavior4o'h .... . 1. ~"''''.... ~ "" non h .... 'r> .1 U ...."'U . 1 llu . 4o'h .... .1 .

    WAA~ ~A~~ &~A 'v ~- ~~A ~~ 'S: ~AJ A ". - J ~~AAAO ~AA~

    mat = N[h[n] I. lambda -) 1/10, 20];Ii = Sort[Eigenvalues[mat]]; Ii [[1]]

    ft ..... ",h4o o'n +'h .... ~"'p uo:>l ......'" ~"'''' .... ')f\ o:>nrl .... Af\.~ WAA~ &~AA~ . AAAO &~A _~ ~AA~ 'v &~.

    co (20) = 0.559146327396 ... ,co (40) = 0.559146327183 ....

    Tneretore, tor n - ~u we nave an accuracy 01 aoout mne slgmncant ngures.Higher energies can only be determined with less accuracy. We obtain

    clO (20) = 17.333 ... ,~'I'o\ ..... n .....

    ClO \

  • 2.1 The Quantum Oscillator 51T, D.' 'l1 .1, '-' -' r. , ., r. .. rpl. ,........... "'0' ~ .....' ... v .......J ,...u. .LVLU. ~~.~~... .LV.L V"".L '''-''- .L , ... ,

    tne two upper energIes are representea In an entIrelY Incorrect manner. inFig. 2.3, on the other hand, we have included twenty levels. In this case, thenumerical solution of the eigenvalue equation yields a very precise result for. ~ . .~. . ... . ..tne Dve loWeSt energIes. .Lne energIes, as well as tneu separatIOns, Increase as

    the anharmonicity parameter ,\ increases.

    10 ____

    Q -----

    '1-/32 _==---------1

    o

    Exercises

    0.2 0.4 0.6lambda

    0.8~lg. ~.3. The nve lowest en-

    1 ergy eIgenvalues as a func-tion of the anharmonicityparameter A

    we conSIaer a quantum partICle In one UlmenSlOn In a aouOle-weu potentIal.For the Hamiltonian we use the dimensionless form

    1 nr~.w t.hp .1~

    2. Calculate the four lowest energy levels.3. Plot the wave functions of the four lowest levels together with the poten-

    t.i~JAI A " y y .,. y r 2 -' 4 y. ,1 L

    "%. '-J'uc "au CWOU lIUC U.L '1 CW.lU '1 LJ UJ C,A-pressIng the operators In terms ot a and ai, analogously to l~.4). Uoesthis improve the results?

    T,'

    Schwabl F. (1995) Quantum Mechanics. Springer, Berlin, Heidelberg, NewYork

  • 52 2. Linear Equations

    Ohm's law is a linear relation between current and voltage. It is still true formonofrequency alternating currents and alternating voltages, if capacitorsan In uc lve COl s are represen e y comp ex lmpe ances. e equa Ionseven remain valid for the general case of passive electrical networks, if onechooses an appropriate representation for currents and voltages in complexspace. For a given frequency, they can be solved relatively easily by com-

    uter and with the Fourier transformation the out ut volta e can then be

    Physics

    iwt

    where Vo and 10 are complex quantities whose phase difference indicates howmuch the current oscillation precedes or lags behind the voltage oscillation.

    with a com lex im edance Z. For an ohmic resistance R for a ca acitanceC, and for an inductance L, Z is given by

    1Z = R, Z = -.- , Z = iwL , (2.11)where R, C, and L are real quantities, measured for example in the units ohm,farad, and henry. In an electric network, the following conservation laws, alsoknown as Kirchhoff's laws, are valid:

    wing 0 ar e conserv i n, into the sum of the outgoing currents at every node.

    2. Along any path, the partial voltage drops across each element add up tothe total voltage over the path.

    which determines all unknown currents and voltages.As a simple example, we consider an L-C oscillatory circuit which is con-

  • 2.2 Electrical Circuits 53

    R T....~

    IIe IL

    c::>

    '1 ,., c::> T 'T'I '-' 01 .LJ Yo

    01

    r Fig. 2.4. Series connection of re-I slstance ana ~v oscUlatory Clr-

    CUlt

    transient, have the same frequency as the input voltage. In this case, thet" .. .

    "'....... }.,. .....1.-:1

    ~~ '0 . .." .......

    Voltage addition: VR + Vo = Vi ,Current conservation: IR = Ie + IL ,

    ........ . 9 P ~ Y ,--vnms laW. VR - n lR, ~..I:;.u:)

    1Vo - :-c le ,

    lWVo = iwLIL .

    .ror a given input VOltage Vi, tnese Dve equations, wnicn in tlllS simple caseare easily solved without a computer, determine the five unknowns VR, Yo,IR, Ie, and IL. Independently of R, the magnitude of the output voltage Voalways reaches a maximum at w = l/VLO; at this frequency the impedanceof the oscillatory circuit is infinite.

    TTl 1i'1.... ') ~ u.rO h~"o _1 _1 tho h" _1 _1"'"

    . . If",0' . - ..- oJ -0 .

    capacitor 0 and an inductance L are connected in series, then the impedanceat the frequency w = l/VLO is minimal. Consequently, we expect a maximal

    n .....14-~~,", fnr thl~ !:at thl~ r 'T'hl~ 1~ 1 "1 h"

    '''- '-' .. oJ 'J

    t" n .I.o.l,u:: '11.10 LWU .. .

    Voltage addition: fa ( R + iW~ + iwL) + Yo = V; ,C LR

    r--t J- ~OOOO'l

    C)I

    Vi C C)I L VoC)I~ ......

    - - ....I: 11:). -'i.i.J. -,.J . ~

    I tlOn 01 .It--Li -lJ comoina-tlon ana .L- -v OSCillatorycircuit

  • 54 2. Linear Equations

    urrent conservation:

    resistances R, Vo becomes much larger than Vi. This can be made plausible bythe following consideration: For low frequencies, the behavior of the parallel

    input signals one obtains the corresponding superposition of the output volt-ages. In particular, one can expand any periodic input voltage Vi(t) with

    (n)W n = 21t"n T to obtain an output voltage Vo Wnoutput signal is given by

    (2.14)

    eq1 = {vr + vo == 1, ir == ic + iI, vr == ir r,vo == ic/(I omega c), vo == Iomega L ill

    the variable eql. With

  • 2.2 Electrical Circuits 55

    the system of equations is solved for the specified variables. Because systemsof equations generally have several solutions, Solva returns a list with lists

    As an example of a non-sinusoidal input voltage Vi(t) we choose a saw-tooth voltage with the period T, which we probe at N equidistant points in

    _ ((r-l)T)ar = Vi (tr ) = Vi N , r = 1, ... ,N ,

    or

    ourier trans ormation we 0

    .(8 - 1)(r - 1)N

    N

    ) 1 .(8 - l)trVi (tr =-- bs exp 21l'1~-~-

    We cannot use the Fourier transformation itself here, but have to use theinverse transformation instead, so that the sign in the argument of the ex-

    N8 = 1, ... , 2 '

    The inverse transformation, which in this case is the Fourier transformation

  • 56 2. Linear Equations

    , as can a so e seen

    to just a sinusoidal oscillation with the frequency W = W r .Basically, for f < 1/2 and R = 200 S1, for example, only the multiple of

    27rIT closest to Wr will be filtered out. By contrast, for f > 1 and a broadresonance all harmonics 0 27r T are included and a distorted co of the

    For the second example, the series connection of R-C-L combinationand L-C oscillatory circuit (Fig. 2.5), Mathematica, again with Vi = 1, gives

    omega omega

    sharper the resonance

  • 2.2 Electrical Circuits 57

    -0.

    0.5 1.5 2 2.5 3 0.5 1 1.5 2.5 3

    1

    output of the filter for f = 1 and R = 2700 n (right)

    1.5 2 2.5 3tIT

    0.5

    0.80.6 0.4 :

    .%0.2 :> 0~:------1'--~--+----:----t----1

    1.5 2 2.5 3tIT

    o 0.5

    0.30.20.1

    c . :'0 OJ-L.~:~+4-+-.............-+-:;...++-0---+---;--1-1--1> -0.1 : i

    ,

    copy of the input signal that results for f = 3 and R = 5 n (right)

    For R = 0, i.e., if the ohmic resistance is equal to zero and the circuit istherefore loss-free, the denominator vanishes at

    w=

    first for a general element with a complex impedance Z, through which a

  • 58 2. Linear Equations

    Fig. 2.9. Magnitude of theoutput voltage for the net-work of series and parallel cir-

    lon, 30n, and 90n

    P = ~ (Re I (t) Re V (t) + ImlI (t) 1m V (t) )1

    = ~ (IzVi + IzVz)1

    = - z

    where we have set Vz = ZIz at the end. For the ohmic resistance R, t epower is accordingly ~(w) = IIR(w)12 R12. We compare this to the power Po,which results if all coils and capacitors in our network are short-circuited,i.e. i t e in ut vo ta e i is connecte nect to t e resIstor ,so t at onegets IR = ViiR, and therefore Po = IViI 2 /(2R). The power ratio P(w)1Pois shown in Fig. 2.10 for R = 10 f!. At both resonance frequencies the coilsand capacitors appear to be completely conductive, while at w = 1 ..jLC the

    Exercises

    1. Calculate and draw Vo (w).. .

    issipation in t e two resistances as a unction 0 w.

  • 0.2

    Iterature

    2.3 Chain Vibrations 59

    Fig. 2.10. The power P(w)dissipated in the ohmic resis-

    connected directly to R

    Crandall R.E. (1991) Mathematica for the Sciences. Addison-Wesley, Red-wood City, CA

    2.3 Chain Vibrations

    the model solid can be represented by superposition of such eigenmodes.

    SICS

    We consider a chain consisting of pointlike masses ml and m2, which wedesignate as light and heavy atoms respectively, for sake of simplicity. Theparticles are to be arranged in such a way that one heavy atom follows threei t ones. The unit cell of len th a thus contains four atoms. Onl nearest

    neighbors shall interact with one another. We limit our considerations tosmall displacements, Le., the forces are to be linear functions of the shifts ofthe masses, as indicated in the s rin model shown in Fi 2.11.

    n,

    and tn be the displacements of the light atoms from their rest positions, and

  • 60 2. Linear Equations

    Fig. 2.11. Linear chain consisting of two types of atoms which are connected toeach other by elastic forces

    mtSn = 1 (tn + Tn - 2sn) ,mt in = 1 (Un + Sn - 2tn) ,

    (2.17)

    , ,

    hold for every unit cell n E Z. For a finite chain consisting of N unit cellswe assume periodic boundary conditions, that is, we think of it as a ringlike

    . .

    ,

    invariant under the translations {Tn, Sn, tn, Un} --+ {Tn+k' Sn+k, tn+k, Un+k},k = 1,2, ... , N, (2.17) can be solved by applying a Fourier transformation.

    X n (t) = = S (q) exp (iqan iwt) , (2.18)

    where, owing to the periodic boundary conditions, q can only take the valuesqv = 21rv/(Na) , v= -N/2+1, ... ,N/2. Then

    ields- 1 0 - le-iqa21 -I 0

    which is a generalized eigenvalue equation of the type

    , ,

    w2 (q) and the corresponding normal modes S(q) for a given value of q. In our

  • 2.3 Chain Vibrations 61

    M-1F8 = >'8 . (2.22)

    This is an ordinary eigenvalue equation for the positive semidefinite Hermi-tian matrix M-1/ 2 FM-1/ 2 with the eigenvector M1/ 28.

    The ei enmodes Xn t = 8 l qll exp iqllan iWlIlt thus obtained are par-

    gously to the electrical filters (Sect. 2.2), the general solution can be ob-tained by a superposition of the eigenmodes. From the complex conjugate of

    The coefficients elll, which are not yet determined, are fixed by the initial

    Algorithm and Results

    The 4 x 4 matrix (2.22) does not represent any particular challenge to ananal tical solution of the ei envalue e uation. If we consider several differenttypes of atoms, or the corresponding two-dimensional problem, however, thematrices become so large that only a numerical determination of the vibra-tion modes is ossible. We want to demonstrate the latter usin our sim Ie

    choosing a = 1:

    matt = { { 2f t -ft Ot -f*Exp[-I q]}t{ Ot -ft 2f t -f}t{-f*Exp[I q]t Ot -ft 2f} }

    case, Mathematica is still capable of specifying the eigenvalues in a general

  • 62 2. Linear Equations

    nested square and cube roots;

    {x.-Pi,Pi.Pi/50}]

    Flatten[ Table [Map[{#[[1]].Sqrt[#[[2,k]]]}l. eigenlist],{k,4}], 1]

    in Fig. 2.12. As we can see, the allowed frequencies of the lattice vibrationsform four bands. The lowest branch represents the so-called acoustic phonons,

    3r.::::=============12.5

    ~bO

    eo

    Fig. 2.12. The frequencies of

    .. .. .. 54(0)

    .. .. 53 (0)

    e---- ;0 e---- .. 52 (0)

    1

    Fig. 2.13. Eigenmodes of the chain for q = 0

  • 2.4 The Hofstadter Butterfly 63

    Exercise

    Investigate the two-dimensional vibrations of your single-family home. Fiveequal masses m are coupled by springs, and the potential between neighboringmasses is

    D 2V (r r) - - (Ir - r 1 - a .)~, J - 2 ~ J ~J ,the sides and the roof, and aij = V2l for the two diagonals.

    Calculate the frequencies of the vibrations for small displacements and

    Literature

    Goldstein H. 1980 Classical Mechanics. Addison-Wesle Readin MAKittel C. (1996) Introduction to Solid State Physics. Wiley, New York

    Linear equations can have intriguing solutions. This becomes especially ap-parent in the case of a crystal electron in a homogeneous magnetic field. Theelectron's ener s ectrum as a function of the stren th of the rna netic eldhas a complicated structure reminiscent of a butterfly. This problem was in-vestigated in 1976 by Douglas Hofstadter. Amazingly, the differences betweenrational and irrational numbers become evident in this s ectrum. We want

    butterfly.

  • 64 2. Linear Equations

    We model an electron on a square lattice by localized wave functions andmatrix elements for jumps between nearest neighbors. In such a tight-binding

    .. . . .

    (k) = 0 (cos kxa + cos kya) , (2.25)where a is the lattice constant, 40 is the width of the energy band, and

    t e vector potenti an p is t e momentum operator. For a magnetic field ofmagnitude B perpendicular to the x-y plane one can choose A = (0, Bx, 0).Thus one obtains the Schrodinger equation

    E cp (x, y) = 0 cos Ii: + 0 cos Ii: + cp (x, y) . (2.26)Owing to the identity cos a = [exp(ia) + exp(-ia)] /2, and because the termex ia is the translation 0 erator that effects a shift b one lattice

    Ecp(x,y) = ~O [cp(x+a,y)+cp(x-a,y)

    + ex

    pIes cp(x, y) with the amplitudes at the four neighboring sites. For the y-dependence of the wave function we assume a plane wave,

    and with the dimensionless variables m = x/a and u = a2eB/ he we finally

    m

    Here, the energy E is measured in units of 0/2. This discrete Schrodingerequation contains only the parameters v and u. The parameter v determinest e -com onent 0 t e momentum w i e u is t e ratio 0 t e rna netic uxa2 B through the unit cell to a flux quantum he/e.

    With this equation we have mapped a two-dimensional lattice electrononto a particle that jumps alon a chain in a periodic cosine potential. The

    ,

    (= 1 in units of m). Here one can already see the difference between rational

  • 2.4 The Hofstadter Butterfly 65

    The eigenstates and the corresponding energies are classified by k and v. Ifone writes (2.29) in matrix form in the following manner,

    with

    then the q-fold iterated equation combined with (2.30), namely

    Trace Mq (E) = 2coskq. (2.34)

    or rational num ers u = p q t ere are at most q energy an s w IC onecan calculate, in principle, from (2.34). In the vicinity of any rational num-ber there are numbers with arbitrarily large q as well as irrational numbersq ~ 00, owever. onsequent y, as a unctIOn 0 u, t ere are spectra WIt

    large numbers of energy bands next to each spectrum with few bands. Here,the difference between rational and irrational numbers becomes evident inphysics.

    Algorithm

    1 and q - 1, but select only those p for which p and q are relatively prime.

  • 66 2. Linear Equations

    The assumption that {'l/Jm} is, for example, an odd function of m, thatis 'l/J-m = -'l/Jm, first leads us to 'l/Jo = 0 and then, taken together with the

    'l/Jq/2 +r = -'l/J-q/2 -r = -'l/Jq/2-r

    o o o

    (2.35)

    en-

    Ao'l/Jo = E'l/Jo , where Ao =o 1

    1 0.(2.36)

    appropriate here, we want to demonstrate briefly that the treatment of thosewave functions that are even in m leads to a very similar problem.

    q'l/Jq/2 +r = 'l/J-q/2 -r = 'l/Jq/2 -r for r = 1,2, ... , 2 - 1 .

    ('l/Jo, 'l/Jl, ... , 'l/Jq/2)T = 'l/Je of the wave function has the form

    (2.37)

  • 2.4 The Hofstadter Butterfly 67

    o

    Ae1jJe = E1jJe, where Ae = o 1

    This two-part recursion formula is completed by the initial values

    PI (E) = Vi - E and Po (E) = 1 . (2.40), 0 q -

    The special importance of the polynomials Pn(E), however, comes fromthe fact that they form a so-called Sturm sequence: Sturm sequences contain

    Po (E), PI (E), P2 (E), ... , Pq/2-1 (E) ,then one obtains the result:

    q -is equal to c(E2 ) - c(E1 ).

    C(Ei) and C(Ei+d then tell us whether there are any eigenvalues between Eiand Ei+l. The region in which any energy eigenvalues can be found at all

    . .

    n

    IE - aiil < ~ laijl (2.41)j=l,j:#

    j=l,j#i ijconclude that the eigenvalues fall between -4 and 4.

  • 68 2. Linear Equations

    P2 - Po

    Pn (E) = (Vn - 1 - E) Pn-l (E) - Pn-2 (E) for n = 3,4, ... , ~ ,

    urm sequ nces,and (2.42), are almost identical to the Harper equation itself, for (2.29) leadsto the following relations for the odd wave functions "p-m = -"pm with the

    the P loop, where a(p, q) is varied, the ie loop, in which the energy changesbetween -4 and 4, and the inner loop over m, which is used to determine

    for(q = 4; q < qmax; q+=2){

  • 2.4 The Hofstadter Butterfly 69

    {e = 8.0*ie/MAXY - 4.0 - 4.0/MAXYn = 0;polyold = 1.0; poly = 2.0*cos(si a) - e;if( polyold*poly < 0.0 ) n++

    fore m = 2; m < q/2; m++ )

    polyold = poly; poly = polynev;}

    eigenfunctions has been left out here.

    if(n > nold) action;

    }

    ,

    ((1-E) values to a data file. The function gcd (p J q) used in the third line ofthe program calculates the greatest common divisor of p and q.

    The result of this program can be seen in Fig. 2.14. The energy is plottedon the vertical axis, the parameter a on the horizontal one. The ener y is

    small interval, a point is plotted at the corresponding position.It is surprising and fascinating what a complex, delicate, and appealing

    . .

    , ,

    to any rational number a = min (m and n relatively prime) with a small

  • 70 2. Linear Equations

    flux per unit cell

    Fi . 2.14. Ei envalues of the Har er e uation as a function of q = Ba2i.e. of the ma netic flux throu h the unit cell in units of the flux uantum

    denominator n there e also others with a large denominator, there will al-ways be a large number of bands next to those values of (J that correspondo a sm enomma or. ny lrra lon num er can e apprOXlma e y a

    sequence of rational numbers with increasing denominators. Consequently,there will always be an infinite number of energy bands next to an irrationalnumber. This results in the artistic drawing which, given infinite resolution,resists our ima ination.

    Exercise

    butterfly and conceive an algorithm which bridges the many large holes.

    trons in Rational and Irrational Magnetic Fields. Phys. Rev. B 14:2239

  • 2.5 The Hubbard Model 71

    ,

    statements. Add to this a considerable mathematical apparatus in which theconcept of states has to be introduced and operators have to be explained.

    only be occupied once. In this space of the multiparticle wave functions, theHamiltonian can be represented as a matrix whose eigenvalues specify theener ies of the stationar states.

    analytic methods. But even a numerical solution is not easy to obtain. Thesize of the system and the increase in the number of degrees of freedom turn

    x q m-m mu p y m, wsider an electron gas in a crystal lattice. In dealing with this problem, wehave to take into acc?unt both the repulsive Coulomb interaction betweenthe electrons and their interaction with the ion cores. A simplified descriptionotIS SItuatIOn, w IC stl contams ate essentla e ements, was su estein 1963 by J. Hubbard. Presently this model is being discussed in connec-tion with high-temperature superconductivity. It is, however, still uncertainwhether this model exhibits superconductivity at all.

    In doing this, however, we have to limit ourselves to a few particles.

    Ph sics

    annihilation operators, and the states can be generated by applying operators

  • 72 2. Linear Equations

    annihilation operators as well, so that the Hamiltonian matrix can eventuallybe constructed algebraically.

    e vacuum.

    ctct ... ctN 10) , (2.43)

    (2.44)

    (2.45)

    result is O. The adjoint operator Ck annihilates cpk(r) if present; otherwise,the result is 0 again. The Pauli exclusion principle follows from ctct = 0,

    , kof electrons localized at lattice sites. The index k contains the number of thesite, and the quantum number for the z-component of the spin, represented

    If two electrons occuCoulomb repulsion

    Unktnk.J,. .

    (2.46)osed to feel the

    (2.47)

    , ,q

    the magnitudes of the kinetic and potential energy respectively.

  • 2.5 The Hubbard Model 73

    MH = -t (2.48)

    k=l u

    with Ck+l,u = cl,u and CM+I,u = Clu' For the order of the single-particlestates, we choose

    Thus every multiparticle state can be described by the occupancy numbersof the single-particle states. Then we get, for example:

    ct+ 1{1,0, ... ,O}, {O, ... ,0, I}) = ct+cttCk+ 10)= -c

    tct

    ct

    and

    It M+= -ctt 10) + clt ck+cM+ 10)

    t- It= -1{1,0, ... ,O}, {O, ... ,O})

    Generally, when applying clu or Cku to a state

    the number of particles to the left of ku determines the sign. Therefore wedefine the sign function:

    The function produces as many factors -1 as there are non-zero entries inn in front of the position ku. This fact allows us to write the effect of the

  • 74 2. Linear Equations

    Cku In} = nkusign (kG", n) I{nIt,, 0, ... , nM.tJ} , (2.52)

    The following quantities are conserved in the Hubbard model: the number ofparticles with positive (Nt) and negative (N.J..) spins, the quantum number

    . . .. .

    be reduced to submatrices with a maximum size of 3 x 3.Here, we only want to consider Nt and N.J.. as conserved quantities. Also,

    Once again, we want to use Mathematica to concisely formulate the repre-

    s[arg] , where arg = {{nIt,, nMt} , {nI.J..,"" nM.J..}} (2.53)an nku E e nee t e ea er s ecause we ave to statesand multiply them by scalars. If we were to perform these operations onthe list arg itself, we would get incorrect results. The main manipulations,however, concern the argument of s. For example, one obtains nku from

    After specifying the numbers M, Nt, and N.J.. we use the functionsPermutations [. .. ] and Table [. .. ] to generate the list index, which con-

    index = {{{1,1,O}, {1,O,O}}, {{1,1,O}, {O,1,O}},{{1,1,O}, {O,O,1}}, {{1,O,1}, {1,O,O}},{{1,O,1}, {O,1,O}}, {{1,O,1}, {O,O,1}},

  • 2.5 The Hubbard Model 75

    {{O,l,l}, {O,O,l}}}

    The operator ct has to generate a 1 in the right spot in the argument of s.

    *

    s [plus [k, sigma] [arg]]

    number 0 as well:

    cdagger[k_,sigma_] [0]:= 0

    we still need the operators nklT:

    n[k_,si a_] [0]:=

    Then the Hamiltonian (2.48) of the Hubbard chain can simply be written as

    , ,

    cdagger [k+l, sigma] [c [k, sigma] [vector]] ,{k,sites},{sigma,2} ]+

    u*Sum[n[k,l] [n[k,2] [vector]] ,{k,sites}]

    Here, the length M of the chain is designated by sites. In order to 0 tainthe Hamiltonian matrix, we need the scalar products (niIHlnj) of Ini) withHlnj). Since our multiparticle states In) are orthonormal, we only have to

    e ne t e inearit 0 t e sca ar ro uct:

    scalarproduct[a_,O]:= 0scalarproduct[a_,b_ + c_]:=

  • 76 2. Linear Equations

    h = (hlist = Table[H[s[index[[j]]]]. {j. end}];Table[ scalarproduct[ s[index[[i]]]. hlist[[j]]].

    {i.end}. {.end}])

    g[uu_]:= Sort[Thread[ Eigensystem[N[ h /. {t -> 1.0. u -> uu} ]]]][[1.2]]

    k=l {n}Mathematica's version of the right-hand side of (2.54) is

    Since the sums are interchangeable and can be regarded as scalar products,

    Results

  • 2.5 The Hubbard Model 77

    2u, , , 3

    Coulomb energy and kinetic energy. For U = 0, there is no interaction be-tween the electrons, so we can calculate the energy levels simply by filling

    -2

    U/t for M = 3, Nt = 2, and N~ = 1

  • 78 2. Linear Equations

    fivefold degenerate:twofold degenerate:

    2 =0,3 = 3t.

    model. The average double occupancy rate in the ground state for M = 4sites and the so-called half-filled case, i.e., Nt + N~ = M (in this specific

    . ..

    Hubbard ring with M = 6 sites, Nt = 3, and N~ 3. As moderate asthese numbers may seem, the number of states strongly increases with M,

    . 6 6_

    asM~oo

    and compare the result to the corresponding values for M = 6. Surprisingly,the two curves are not very far apart at all, as can be seen in Fig. 2.18.

  • 2.5 The Hubbard Model 79

    o 2 3 4 5Fig. 2.16. Average double occu-

    6 pancy in the ground state as a func-

    U/t

    Fi . 2.18. Ground state ener ersite for the half-filled band. Thedashed curve is the exact result forM ~ 00, the solid curve gives the65

    42 3o

    -0.4,..-------........--..--------......

    ....(/)8. -0.8e.o -1II)

  • 80 2. Linear Equations...,.

    '-&0....

    The z-component of the spin operator at the site i can be expressed by theparticle number operators nit and nq: Sf = (nit - ni.JJ/2. For the ground

    I _\ 1". L TT." , .J.1 , L 1I..r A .J 1\ T 1\Tn' i:)IJaIJ'lJ IY I VI. IJU'lJ .u VVI.IJ.U .U'.J. "% i:)J.IJ'lJi:) auu J. Yi J. YJ. .&I,

    .,.',

    the spin correlations (11M) ~~:1 (glSf Sf+llg) and (11M) E~:l (glSf Sf+2Ig)as a function of UIt.TO

    ,~uu..L'lJ

    Hirsch J.E. (1985) Two-dimensional Hubbard Model: Numerical SimulationStudy. Phys. Rev. B 31:4403

    T TT roo. rt ., T T':' 11 nn

  • 3. Iterations

    .. ,. . . ,. ,. . . . .1"1. Ul a ;:seL Ul U.l~U LIlalJ l:unven gIven InpUlJ valUeS lJOoutput values. Now if the output itself is part of the domain of the functionconsidered, it can become an input in turn, and the function returns newoutput values. This process can then be repeated indefinitely. While thereare otten no analytic methods to calculate the structural properties of suchiterations of the form Xt+l = f(Xt), they are easily generated on the com-puter. Obviously, one just has to apply the same function f(x) to the resultrepeatedly. We want to demonstrate this with a few examples.

    3.1 Population Dynamics

    Arguably, the best-known IteratIOn ot a nonlInear tunctIOn IS the so-calledlogistic map. It is a simple parabola that projects the real numbers of the unitinterval onto themselves. We want to present it here because every scientistshould know the properties of such an elementary iteration.

    A simnle mechanism leads to comnlex behavior - this is the result of+1-.1' ..l ,. . ,,~ '" ., . 1". . A 1+1-.".......1-. ", "''''1' " .... 1... '"

    U~ ' ..

    '-' ........ .....v~ .u v~.. ~ ....... 'V '-'J .....

    few analytic results on this, anyone can easily reproduce the iteration with apocket calculator. For certain parameter values of the parabola the iterated

    , . .~..l 'n t1-.o "n't 1 'n o:>n , '1'1-.0 00.

    : ..- , ~,. ..

    . . . . . . ,.Ul 1::) .Y .Yc; LU Ul LIle OlJa.l'Lulg Value Ul' .. v ~

    the iteration. A well-defined function definition yields a sequence of numbersthat is practically unpredictable even for a small initial uncertainty. Such a, , . . .. . . .. .

    1;:S ~ .... IPol u,(;'1I(;.' .

    ~ome quantItIes that can be calculated wIth the computer are not justthe result of a mathematical folly; rather, one finds these numbers in manyexperiments near the transition from regular to chaotic behavior. Such auniversality of quantitative values is an additional fascinating aspect of this

    .

  • 82 3. Iterations

    We consider the iteration

    X n +l = 4rxn (1 - xn ) = f (xn ) , n = 0,1,2,3, ... , (3.1)

    hulst, in a work on population dynamics. Here, X n is iterated in the interval[0, 1], and r is a parameter that can be varied in the range [0, 1] as well.

    . .. . .

    In this model, X n is proportional to the population density of a speciesat time n. Its growth is described by a linear contribution 4rxn which,

    If neighboring X n values differ only by small amounts, then n and X n canbe extended to real numbers in a continuous way. If we set

    n

    2dn

    then (3.1) becomes an approximation of the differential equationdx

    with the solution4r -1

    x (n) =-----~---

    00 ,

    1/4 all initial values x(O) > lead to the value X oo = 1 - 1/(4r). Likethe discrete iteration, this equation has a phase transition at ro = 1/4

    . .. .

    owe have for small en:

  • 3.1 Population Dynamics 83

    Therefore, the perturbation co explodes for If'(x*)1 > 1, which correspondsto T > TI = 3/4. We will see that, in this case, the X n jump back and forthbetween the values x* and x* after a few ste s:

    (3.3)

    T, ~ Too - tS'

    From this we can concludeI - 1-1

    (3.4)

    1-+00 T'+I - Tl

    The number tS is called the Feigenbaum constant and has the value tS

    ,

    extremely close values separate after just a few iterations and jump aroundin the chaotic bands seemingly independently. For a quantitative characteri-

    . .

    (3.6)The parameter ,\ is called the Lyapunov exponent; it is a measure of the

    (3.7)

  • 84 3. Iterations

    immediately gets

    Algorithm

    With Mathematica one can obtain an n-fold iteration of a given function,such as f x_ = 4 r x i-x sim usin

    iterf[n_]:= Nest[f,x,n]

    The determination of the bifurcation

    2 Y ovn wunknown variables x* and r" either by hand or by using the Mathematicafunction FindRoot. But we were unable to determine higher r, values this

    Now again, solving the equation

    numerically is not easy. Since this equation has 2'

    - 1 additional fixed points,the function oscillates very rapidly and FindRoot fails. But there is a trick:

    number of Rs in the l-sequence is odd, or by R if it is even. For l = 2, the

  • 3.1 Population Dynamics 85

    ,.I",.. hl~......... .., _1 rv Drv D ....... ,.1 4- l-.~~ 1 rvDT D .... ~ rvD . ,L D~ J .. " ..'4.... "" .. "''''' .. '" ........'4 u .......... "" .. "'.&oJ" "" UU "-' .. " JUDU VU.'V """.~ . ~l'or t - .1, one gets {>J:f,I H H f-oft.

    The inverse iteration is most easily performed in a coordinate systemwhose origin is at (x, y) = (1/2,1/2) and whose two axes are scaled by a

    p . . . . . A . .

    :mcn tnat tne peaK or tne paraOOla in tne new system is at(0,1). In this coordinate system, the original parabola f(x) = 4rx(I - x)takes the form

    n ft\ - 1 "t2J ,-,,/ r -"1

    II l:lnrl ... l:l ....O ...."ll:ltorl ,,; l:lr

    or r = ~ (1 + viI + 4JL)JL = r (4r - 2) .We designate the left branch of the narabola bv or.(E) and the rie:ht one bv9R(e). Then the superstable orbit for l = 2 obeys the equation

    9R (9L (9R (1))) = 0""yo

    1 = 9ii 1 (91:"1 (9ii 1 (0)))with

    . 1 , /1- 11 . . 1 /1- 119R ~'fJ) V ana 9L ~'fJ) V .JL JL

    This finally leads to the following equation for JL:I

    a = 1/ a + .. / a - "fa (3.9)V v

    which can be solved by iteration or by using FindRoot. The sequence CRLRdetermines the signs of the nested roots in (3.9). After the initial CR, whichdoes not enter the eauation above L vields a nositive and R a negative sign.This holds for all superstable periodic orbits. Thus, the orbit of period 5,with the sequence CRLRR, which is located between chaotic bands, is foundat a a value that obevs the followine: eauation:

    I fJL=yJL+VJL-VJL-YP;

    We have programmed the generation of the sequence in Mathematica in thefoP w~.v For p~("h .1. .1 R (T,) WI" . t.hp mnnhpr~ 1 (I)). t.hp ~p_

    ~ ., ., , ", ,

    quence of length 2n is stored as a list period [n] . Initially we define the listperiod[1] ={c, 1} for n = 1, and the doubling of the sequence is done by

    per1odln_J:= per1odlnJ-Join [period [n-l], correct[period[n-l]]]

  • 86 3. Iterations

    sum is even.correct[list_]:=Block[{sum=O,li=list,I=Length[list]},

    Do[sum+=li[[i]],{i,2,1}];If [OddQ [sum] , Ii [[1]] =0, Ii [[1]] =1] ;Ii]

    prec=30maxit=30

    In order to generate and display the orbits XO, Xl , X2 , X3, for all parametersr (or J.t), one should use a fast programming language, if possible, since eachvalue of r requires about 1000 iterations. In principle, however, this is very

    X n , until the X n have come very close to the attractor. Then, one calculates1000 additional values of X n , transforms them into the y-coordinate of the

    xit = 4.*r*xit*(l.-xit);putpixel( r*MAII, (l.-xit)*MAIY,WHITE);

    following function:

  • 3.1 Population Dynamics 87

    }getch();getch();clearviewport();return;

    }

    Results

    fixed points of the fourfold iterated function f(x). These can be seen inFig. 3.2. The function f(4)(x) intersects the straight line y = x eight times,but onl four of those are stable fixed oints. As T is increased attractors ith

    ,...

    Too = 0.89 .... This is clearly visible in Figs. 3.3 and 3.4, in which 1000X n values are plotted for each value of T, after an initial transition period

    0.8

    0.7,....,c:

    ~ 0.6

    n

    Fig. 3.1. Iteration start-ing from Xo = 0.65 usingthe parameter r = 0.87.The X n values move to-wards an attractor of pe-riod 4

  • 88 3. Iterations

    I~ L-----------:t:----~.: ~~m; .. .;0; _-.... N ;;..,;;.~. ~~_:o-.. ......~-.~'~ ~_ ....

    I...

    I

    below a five-cycle; though there is just one band there, one still sees the fivepeaks of the adjacent cycle. It can be shown that only one band with density

    exists for r = 1. In Fig. 3.4, in the chaotic region, one sees many windows with

    baum constant 8. To this end, we calculate the parameters Rl, at which there

  • 0..

    Fi . 3.4. A close-u

    3.1 Population Dynamics 89

    for T between 0.88 and 1

    a parameter value T ~ 0.934,just below the window withperiod 5

  • 90 3. Iterations

    1/

    /./ ........... /

    0.8 / V/ /\

    0.6 / / \/ \f\A I / \~. I /

    0.2 //1/ \

    oV \ Fig. 3.6. Superstable four-cycle0.2 0.4 0.6 0.8 1 with r = 0.874640

    1 /

    /'"

    /

    0.8 / V/ / \

    0.6"

    "

    0.4 I / \I / \

    0.2/~ \'(1/ \ Fi~. 3.7. Three chaotic bands forV , r = 0.9642, just above the large0 0.2 0.4 0.6 0.8 1 window with the three-cycle

    . . ..-

    .1 ~ . . .-

    . . .

    are-0;- VI. LJUlt:) or .?~I II II ,(.'. I lSI 19 tne TTlPT 'lnrl~ or symoollc aynamlcs

    and inverse iteration we find the R, with a precision of 30 digits, of whichonly 12 are printed here:

    fl. ~ 11 "'...,,,....'.LV ,

    Ru = 0.892486401027 ,R12 = 0.892486414339 ,R.o o on.n A 0'"'1.1 71 QO

    '~u

    li14 - U.XUIAW";A 1'(~Ul ,

    R15 = 0.892486417932 .

  • 3.1 Population Dynamics 91

    we find the following approximate values for ~:~ = 4.669201134601

    ~12 = 4.669201587522 ,~13 = 4.669201604512 ,

    ~15 = 4.669201608