We show how Mathematica is used to simplify our work and to support and derive solutions for specific problems.. We further introduce Mathematica functions that are closely related to th
Trang 4New Cairo City
Main Entrance of Al Tagamoa Al Khames
Egypt
Gerd.Baumann@GUC.edu.eg
This is a translated, expanded, and updated version of the original German version of
the work “Mathematica® in der Theoretischen Physik,” published by Springer-VerlagHeidelberg, 1993©
Library of Congress Cataloging-in-Publication Data
Baumann, Gerd.
[Mathematica in der theoretischen Physik English]
Mathematica for theoretical physics / by Gerd Baumann.—2nd ed.
p cm.
Includes bibliographical references and index.
Contents: 1 Classical mechanics and nonlinear dynamics — 2 Electrodynamics, quantum mechanics, general relativity, and fractals.
© 2005 Springer Science+Business Media, Inc.
All rights reserved This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer Science +Business Media, Inc., 233 Spring Street, New York, NY 10013, USA), except for brief excerpts in connection with reviews or scholarly analysis Use in connection with any form of information storage and retrieval, electronic adaptation, com- puter software, or by similar or dissimilar methodology now known or hereafter developed is for- bidden.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
Mathematica, MathLink, and Math Source are registered trademarks of Wolfram Research, Inc.
Printed in the United States of America (HAM)
9 8 7 6 5 4 3 2 1
springeronline.com
Trang 6As physicists, mathematicians or engineers, we are all involved withmathematical calculations in our everyday work Most of the laborious,complicated, and time-consuming calculations have to be done over andover again if we want to check the validity of our assumptions andderive new phenomena from changing models Even in the age ofcomputers, we often use paper and pencil to do our calculations.
However, computer programs like Mathematica have revolutionized our working methods Mathematica not only supports popular numerical
calculations but also enables us to do exact analytical calculations bycomputer Once we know the analytical representations of physical
phenomena, we are able to use Mathematica to create graphical
representations of these relations Days of calculations by hand have
shrunk to minutes by using Mathematica Results can be verified within
a few seconds, a task that took hours if not days in the past
The present text uses Mathematica as a tool to discuss and to solve
examples from physics The intention of this book is to demonstrate the
usefulness of Mathematica in everyday applications We will not give a
complete description of its syntax but demonstrate by examples the use
Trang 7This second edition of Mathematica in Theoretical Physics seeks to
prevent the objectives and emphasis of the previous edition It isextended to include a full course in classical mechanics, new examples
in quantum mechanics, and measurement methods for fractals Inaddition, there is an extension of the fractal's chapter by a fractionalcalculus The additional material and examples enlarged the text somuch that we decided to divide the book in two volumes The firstvolume covers classical mechanics and nonlinear dynamics The secondvolume starts with electrodynamics, adds quantum mechanics andgeneral relativity, and ends with fractals Because of the inclusion ofnew materials, it was necessary to restructure the text The maindifferences are concerned with the chapter on nonlinear dynamics Thischapter discusses mainly classical field theory and, thus, it wasappropriate to locate it in line with the classical mechanics chapter.The text contains a large number of examples that are solvable using
Mathematica The defined functions and packages are available on CD
accompanying each of the two volumes The names of the files on the
CD carry the names of their respective chapters Chapter 1 comments on
the basic properties of Mathematica using examples from different fields
of physics Chapter 2 demonstrates the use of Mathematica in a
step-by-step procedure applied to mechanical problems Chapter 2contains a one-term lecture in mechanics It starts with the basicdefinitions, goes on with Newton's mechanics, discusses the Lagrangeand Hamilton representation of mechanics, and ends with the rigid body
motion We show how Mathematica is used to simplify our work and to
support and derive solutions for specific problems In Chapter 3, weexamine nonlinear phenomena of the Korteweg–de Vries equation We
demonstrate that Mathematica is an appropriate tool to derive numerical
and analytical solutions even for nonlinear equations of motion Thesecond volume starts with Chapter 4, discussing problems ofelectrostatics and the motion of ions in an electromagnetic field We
further introduce Mathematica functions that are closely related to the
theoretical considerations of the selected problems In Chapter 5, wediscuss problems of quantum mechanics We examine the dynamics of afree particle by the example of the time-dependent Schrödinger equationand study one-dimensional eigenvalue problems using the analytic and
Trang 8numeric capabilities of Mathematica Problems of general relativity are
discussed in Chapter 6 Most standard books on Einstein's theory discussthe phenomena of general relativity by using approximations With
Mathematica, general relativity effects like the shift of the perihelion
can be tracked with precision Finally, the last chapter, Chapter 7, usescomputer algebra to represent fractals and gives an introduction to thespatial renormalization theory In addition, we present the basics offractional calculus approaching fractals from the analytic side Thisapproach is supported by a package, FractionalCalculus, which is notincluded in this project The package is available by request from the
author Exercises with which Mathematica can be used for modified
applications Chapters 2–7 include at the end some exercises allowingthe reader to carry out his own experiments with the book
Acknowledgments Since the first printing of this text, many people
made valuable contributions and gave excellent input Because thenumber of responses are so numerous, I give my thanks to all whocontributed by remarks and enhancements to the text Concerning thehistorical pictures used in the text, I acknowledge the support of thehttp://www-gapdcs.st-and.ac.uk/~history/ webserver of the University of
St Andrews, Scotland My special thanks go to Norbert Südland, whomade the package FractionalCalculus available for this text I'm alsoindebted to Hans Kölsch and Virginia Lipscy, Springer-Verlag NewYork Physics editorial Finally, the author deeply appreciates theunderstanding and support of his wife, Carin, and daughter, Andrea,during the preparation of the book
Ulm, Winter 2004
Gerd Baumann
Trang 102.5.4 Two-Particle Collisons and Scattering 240
Trang 112.7.3 Hamilton's Principle 3132.7.4 Symmetries and Conservation Laws 341
2.8.4 Hamilton's Equations and the Calculus of Variation 366
2.10.7 Force-Free Motion of a Symmetrical Top 4672.10.8 Motion of a Symmetrical Top in a Force Field 471
3.3 Solution of the Korteweg-de Vries Equation 492
Trang 123.3.1 The Inverse Scattering Transform 4923.3.2 Soliton Solutions of the Korteweg–de Vries
3.4 Conservation Laws of the Korteweg–de Vries Equation 5053.4.1 Definition of Conservation Laws 5063.4.2 Derivation of Conservation Laws 5083.5 Numerical Solution of the Korteweg–de Vries Equation 511
3.7.2 Conservation Laws for the KdV Equation 5173.7.3 Numerical Solution of the KdV Equation 518
Trang 135.3 One-Dimensional Potential 595
5.7 Second Virial Coefficient and Its Quantum Corrections 6425.7.1 The SVC and Its Relation to Thermodynamic
6.4.6 Cartesian Space in Cylindrical Coordinates 7366.4.7 Euclidean Space in Polar Coordinates 737
6.5.1 The Schwarzschild Metric in Eddington–Finkelstein
Trang 146.5.2 Dingle's Metric 7426.5.3 Schwarzschild Metric in Kruskal Coordinates 748 6.6 The Reissner–Nordstrom Solution for a Charged
7.4.1 Multifractals with Common Scaling Factor 798
Trang 15This first chapter introduces some basic information on the computer
algebra system Mathematica We will discuss the capabilities and the scope of Mathematica Some simple examples demonstrate how
Mathematica is used to solve problems by using a computer
All of the following sections contain theoretical background information
on the problem and a Mathematica realization The combination of both
the classical and the computer algebra approach are given to allow acomparison between the traditional solution of problems with pencil andpaper and the new approach by a computer algebra system
1.1 Basics
Mathematica is a computer algebra system which allows the following
calculations:
æ symbolic
Trang 16æ numeric
æ graphical
æ acoustic
Mathematica was developed by Stephen Wolfram in the 1980s and is now
available for more than 15 years on a large number of computers fordifferent operating systems (PC, HP, SGI, SUN, NeXT, VAX, etc.)
The real strength of Mathematica is the capability of creating customized
applications by using its interactive definitions in a notebook Thiscapability allows us to solve physical and engineering problems directly onthe computer Before discussing the solution steps for several problems oftheoretical physics, we will present a short overview of the organization of
æ the standard Mathematica packages
æ the MathSource library
æ the programs written by the user
The kernel is the main engine of the system containing all of the functions defined in Mathematica The frontend is the part of the Mathematica
system serving as the channel on which a user communicates with thekernel All components interact in a certain way with the kernel of
Mathematica.
Trang 17Figure 1.1.1 Mathematica system
The kernel itself consists of more than 1800 functions available after the initialization of Mathematica The kernel manages calculations such as
symbolic differentiations, symbolic integrations, graphical representations,evaluations of series and sums, and so forth
The standard packages delivered with Mathematica contain a
mathematical collection of special topics in mathematics The contents ofthe packages range from vector analysis, statistics, algebra, to graphics and
so forth A detailed description is contained in the technical report Guide
to Standard Mathematica Packages [1.4] published by Wolfram Research
Inc
MathSource is another source of Mathematica packages MathSource
consists of a collection of packages and notebooks created by
Mathematica users for special purposes For example, there are
calculations of Feynman diagrams in high-energy physics and Liesymmetries in the solution theory of partial differential equations
MathSource is available on the Internet via
http://library.wolfram.com/infocenter/MathSource/
Trang 18The last part of the Mathematica environment is created by each individual user Mathematica allows each user to define new functions extending the functionality of Mathematica itself The present book
belongs to this part of the building blocks
The goal of our application of Mathematica is to show how problems of
physics, mathematics, and engineering can be solved We use thiscomputer program to support our calculations either in an interactive form
or by creating packages which tackle the problem We also show how non
standard problems can be solved using Mathematica.
However, before diving into the ocean of physical problems, we will first
discuss some elementary properties of Mathematica that are useful for the
solutions of our examples In the following, we give a short overview of
the capabilities of Mathematica in symbolic, numeric, and graphical
calculations The following, section discusses the interactive use of
Mathematica.
1.1.2 Interactive Use of Mathematica
Mathematica employs a very simple and logical syntax All functions are
accessible by their full names describing the mathematical purpose of thefunction The first letter of each name is capitalized For example, if we
wish to terminate our calculations and exit the Mathematica environment,
we type the termination function Quit[] This function disconnects the
kernel from the frontend and deletes all information about our calculations
Any function under Mathematica can be accessed by its name followed by
a pair of square brackets which contain the arguments of the respective
function An example would be Plot[Sin[x],{x,0,p}] The termination function Quit[] is the one of the few functions that lacks an argument.
After activating Mathematica on the computer by typing math for the interactive version or mathematica for the notebook version, or using just
a double click on the Mathematica icon, we can immediately go to work.
Trang 19interactive or Shift plus Return in the notebook version The result is asimplified expression of the rational number.
69 ê 15
23
ccccccc
5
The input and output lines of Mathematica carry labels counting the
number of inputs and outputs in a session The input label is In[no]:= and the related output label is Out[no]= Another example is the
exponentiation of a number Type in and you will get
2 ^ 10
1024
The two-dimensional representation of this input can be created by using
Mathematica palettes or by keyboard shortcuts For example, an exponent
is generated by CTRL+6 on your keyboard
Trang 2010
In addition to basic operations such as addition (+), multiplication (*),
division (/), subtraction (-), and exponentiation (^), Mathematica knows a
large number of mathematical functions, including the trigonometric
functions Sin[] and Cos[], the hyperbolic functions Cosh[] and Sinh[], and
many others All available Mathematica functions are listed in the
handbook by Stephen Wolfram [1.1] Almost all functions listed in the
work by Abramowitz and Stegun [1.2] are also available in Mathematica.
1.1.3 Symbolic Calculations
By symbolic calculations we mean the manipulation of expressions usingthe rules of algebra and calculus The following examples give a quick
idea of how to use Mathematica We will use some of the following
functions in the remainder of this book
A function consists of a name and several arguments enclosed in squarebrackets The arguments are separated by commas One function
frequently used in the solution process is the function Solve[] Solve[]
needs two arguments: the equation to be solved and the variable for which
the equation is solved For each Mathematica function, you will find a
short description of its functionality and its purpose if you type the name
of the function preceded by a question mark For example, the description
of Solve[] is
? Solve
Solve @eqns, varsD attempts to solve an equation or set
of equations for the variables vars Solve @eqns,
vars, elims D attempts to solve the equations
for vars, eliminating the variables elims More…
Trang 21pops up and delivers a detailed description of the function Each help pagecontains additional examples demonstrating the application of the function.
The help facility of Mathematica ? or ?? always gives us a short
description of any function contained in the kernel For a detailed
description of the functionality, the reader should consult the book byWolfram [1.1]
Let us start with an example using Solve[] applied to a quadratic equation
equivalent to the derivative function D[] Both functions are used for
ordinary and partial differentiation:
Trang 22The same calculation is carried out by the symbolic notation in theStandardForm:
Mathematica allows different kinds of input style The first or input
notation is given by the spelled out mathematical name The secondstandard form is a two-dimensional symbolic representation The third way
to input expressions is traditional mathematical forms The integral fromabove then looks like
‡ t a ‚ t
t a+1
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ
a + 1
Each input form has its pro and con The spelled out input form is always
compatible with the upgrading of Mathematica The traditional form has
some features which prevents the compatibility but increases thereadability of a mathematical text In the following, we will mix thedifferent input forms and choose that one which is appropriate for therepresentation For interactive calculations, we use the standard ortraditional form; for programming, we switch to input notations Thedifferent representations are also available in the output expressions They
can be controlled by the Cell button in the command menu of Mathematica.
Next, let us examine some operations from calculus The calculation of alimit is given by
Trang 23Limit A ccccccccccccccccccc Sin @tD
t , t 0E
1023
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ
1024
The result of this calculation is represented by a rational number
Mathematica is designed in such a way that the calculation results are
primarily given by rational numbers This kind of number representationallows a high accuracy in the representation of results For example, weencounter no rounding errors when using rational representations ofnumbers
The Laplace transform of the function Sin[t] is calculated using the standard function LaplaceTransform[]:
LaplaceTransform @Sin@tD, t, sD
1
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ
s2+1
Trang 24Ordinary and some kind of partial differential equations can be solved
using the function DSolve[] A practical example is given by the relaxation
equation u ' + a u = 0 The solution of this equation follows from
DSolve @ t u @tD + D u@tD m 0, u, tD
88u Ø Function@8t<, ‰ -t a c1D<<
In addition to the standard functions, Mathematica allows one to
incorporate standard packages dealing with special mathematical tasks (seeFigure 1.1.1) To load such standard packages, we need to carry out the
Get[] function abbreviated by << followed by the package name Such a
standard package is available for the purpose of vector analysis.Calculations of vector analysis can be supported using the standardpackage VectorAnalysis, which contains useful functions forcross-products of vectors as well as for calculating gradients of scalarfunctions Some examples of this kind of calculation follow:
<< Calculus`VectorAnalysis`
CrossProduct @8a, b, c<, 8d, e, f<D
8b f - c e, c d - a f , a e - b d<
A more readable representation is gained by applying the function
MatrixForm[] to the result:
CrossProduct @8a, b, c<, 8d, e, f<D êê MatrixForm
Trang 25of a vector or a matrix The disadvantage of this output form is that it isnot usable in additional calculations Another function available in the
package VectorAnalysis is a gradient function for different coordinate
systems (cartesian, cylindrical, spherical, elliptical, etc.) The following
example applies the Grad[] in cartesian coordinates to a function
depending on three cartesian coordinates x, y, and z:
Grad @f@x, y, zD, Cartesian@x, y, zDD êê MatrixForm
zzzzzzzzz
These examples give an idea of how the capabilities of Mathematica
support symbolic calculations
1.1.4 Numerical Calculations
In addition to symbolic calculations, we sometimes need the numerical
evaluations of expressions The numerical capabilities of Mathematica
allow the following three essential operations for solving practicalproblems
The solution of equations, for example the solution of a sixth-order
To evaluate a definite integral in the range x œ@0, ¶D, you can use the
numerical integration capabilities of NIntegrate[] An example from
statistical physics is
Trang 26to solve a nonlinear ODE The function NDSolve[] may help you tackle
such problems An example of a second-order nonlinear ODE used in theexamination of nonlinear oscillators demonstrates the solution of the initial
value problem y '' - y2+2 y = 0, yH0L = 0, y' H0L = ÅÅÅÅ12 The initial value
problem describes a nonlinear oscillator starting at t = 0 with a vanishing
elongation and an initial velocity of ÅÅÅÅ12 The formulation in Mathematica
The result of the numerical integration is a representation of the solution
by means of an interpolating function
The above three examples serve to demonstrate that Mathematica is also
capable of handling numerical evaluations There are many other functionswhich support numerical calculations As a rule, all functions which
involve numerical calculations start with a capital N in the name.
Trang 271.1.5 Graphics
Mathematica supports the graphical representation of different
mathematical expressions Mathematica is able to create two- and
three-dimensional plots It allows the representation of experimental datagiven by lists of points, by parametric plots for functions in parametricform, or by contour plots for three-dimensional functions It further allows
the creation of short motion pictures by its function Animation An
overview of these capabilities is given next
As a first example of the graphical capabilities of Mathematica, let us
show how simple functions are plotted The first argument of the plot
function Plot[] specifies the function; the second argument denotes the
plot range All other arguments are options which alter the form of the plot
in some way A standard example in harmonic analysis is
Plot @Sin@xD, 8x, S, S<, AxesLabel 8"x", "Sin@xD"<D;
-1 -0.5
0.5
1 Sin @xD
This plot can be improved in several directions: Sometimes you need agrid or other fonts for labeling or you prefer a frame around the plot.These properties are accessible by specifying the appropriate options ofthe following function:
Trang 28Plot @Sin@xD, 8x, S, S<,
AxesLabel 8StyleForm@"x", FontWeight "Bold",
FontFamily "Tekton"D, StyleForm@"Sin@xD",
FontWeight "Bold", FontFamily "Tekton"D<,
Frame > True, GridLines Automatic,
AxesStyle 8RGBColor@1, 0, 0D, Thickness@0.01D<, TextStyle 8FontSlant "Italic", FontSize 12<D;
1
0.5
0 0.5
1
x Sin @xD
In three dimensions, we use Plot3D[] to represent the surface of a
function A following example showing the surface in a rectangular water
tank The arguments of Plot3D[] are similar to the function Plot[] The
first specifies the function; the second and third specify the plot range; allothers are optional
Trang 29Plot3D @Sin@xD Cos@yD, 8x, S, S<, 8y, 2 S, 2 S<,
AxesLabel > 8"x", "y", "z"<, PlotPoints > 35,
TextStyle 8FontSlant "Italic", FontSize 12<D;
Sometimes you may know a solution of a problem only in a parametricrepresentation Consider, for example, the motion of an electron in aconstant magnetic field For such a situation, the track of the electron isdescribed by a three-dimensional vector depending parametrically on time
t To represent such a parametric path, you can use the function
ParametricPlot3D[] The first argument of this function contains a list
which describes the three coordinates of the curve A fourth element of thislist, which is optional, allows you to set a color for the track We used in
the following example the color function Hue[] The second argument of the function ParametricPlot3D[] specifies the plot range of the parameter All other arguments given to ParametricPlot3D[] are options changing
the appearance of the plot
Trang 30ParametricPlot3D @82 Sin@tD, 5 Cos@tD, t, Hue@0.4D<, 8t, 0, 4 S<, Axes > FalseD;
Another example is the movement of a planet around the Sun, for whichthe solution of the problem is in implicit form According to Kepler`stheory (see Chapter 2, Section 2.5), a planet moves on an elliptical trackaround the Sun The path of the planet is described in principal by a
formula like x2+2 y2=3 To graphically represent such a path, we can
use a function known as ImplicitPlot[] in Mathematica This function
becomes available if we load the standard package
Graphics`ImplicitPlot` A representation of the hypothetical planet track
in x and y follows for the range x œ@-2, 2D by
<< Graphics`ImplicitPlot`
Trang 31pl1 = ImplicitPlot@x 2 + 2 y 2 == 3,
8x, 2, 2<, PlotStyle > RGBColor@1, 0, 0DD;
-1 -0.5
0.5 1
The color of the curve is changed from black to red by the option
PlotStyleÆRGBColor[1,0,0].
If you have a function which is defined over a large range in x and y, such
as in dynamical relaxation experiments, it is sometimes useful to representthe function in a log-log plot For example, to show the graph of a scaling
function like f HxL = x1.4 in the range x œ@1, 103D, we can use
LogLogPlot[] from the standard package Graphics`Graphics` to show
the scaling behavior of the function We clearly observe in the double
logarithmic representation a linear relation between y and x which is
characteristic for scaling (see Chapter 7 for more details)
Trang 32<< Graphics`Graphics`;
LogLogPlot @x 1.4
, 8x, 1, 1000<, FrameLabel > 8"x", "y"<,
GridLines > Automatic, Frame > TrueD;
20 50 100 200 500 1000
x
100 200 500 1000
2000
5000
10000
If you have to handle data from experiments, Mathematica can do much of
the work for you The graphical representation of a set of data can be done
by the function ListPlot[] This function allows you to plot a list of data The input here is created by means of the function Table[] The dataset, which we will represent by ListPlot[] consists of pairs 8x, sinHxL e- ÅÅÅÅ4x< in
the range x œ@0, 6 pD The data are located in the variable tab1 The
graphical representation of these pairs of data is achieved by the function
ListPlot[] using the dataset tab1 as first argument All other arguments are
used to set temporary options for the function
Trang 33In[10]:= tab1 = TableA9x, Sin@xD Æ cccccc x 4 =, 8x, 0, 6 S, 0.2<E;
ListPlot @tab1, PlotStyle >
8RGBColor@0, 0, 0.500008D, PointSize@0.015D<,
AxesLabel > 8"x", "y"<, PlotRange > AllD;
If you need to represent several sets of data in the same figure, you can use
the function MultipleListPlot[] contained in the standard package Graphics`MultipleListPlot` An example for two sets of data tab1 and tab2 is given below
<< Graphics`MultipleListPlot`
tab2 = TableA9x, Sin@xD Æ cccccc x 8 =, 8x, 0, 6 S, 0.2<E;
2.5 5 7.5 10 12.5 15 17.5 x -0.2
0.2
0.4
0.6
y
Trang 34MultipleListPlot @tab1, tab2,
AxesLabel > 8"x", "y"<, PlotRange > AllD;
2.5 5 7.5 10 12.5 15 17.5 x -0.4
Sometimes, results found by laborious calculations are poorly represented
by simple pictures and there might by a way to "dress them up" a bit Inmany situations, you can vary a parameter or simply the time period tochange the result in some way The output of a small variation inparameters can be a great number of frames which all show differentsituations To collect all of the different frames in a common picture, you
can use the animation facilities of Mathematica The needed functions are
accessible if we load the standard package Graphics`Animation` By using the function Animate[] contained in this package, you can create, for
example, a flip chart movie for a planet moving around a star Thefollowing animation combines two graphics objects, the first contained in
the symbol pl1 representing the track of the planet and the second
consisting of a colored disk the planet
<< Graphics`Animation`
pl2 = AnimateA9pl1, GraphicsA9RGBColor@0, 0, 1D,
Disk A9 è!!!! 3 Sin @xD, è!!!!!!!!!!! 3 ê 2 Cos@xD=, 0.1E=E=, 8x, 0,
2 S, 0.3<, PlotRange > 881.9, 1.9<, 81.5, 1.5<<E
Trang 35-1.5 -1 -0.5 0.5 1 1.5
-1.5 -1 -0.5
0.5 1 1.5
Note: In the printed version, we replace the animation by a single plotcontaining the different plots distinguished by different colors We use thisprocedure to show the reader how an animation is generated and what kind
of plots are generated
If Mathematica does not provide you with the graphics you need, you are
free to create your own graphics objects By using graphics primitives like
Line[], Disk[], Circle[], and so forth, you can create any two- or
three-dimensional objects you can imagine A simple example to combinelines, disks, squares, and circles for depicting the scattering of a particles
on a gold bar follows
Trang 36<< Graphics`Arrow`;
Show @
Graphics @88RGBColor@0.976577, 0.949233, 0.0195315D, Rectangle @82, 2<, 82, 2<D<,
Line @880, 0<, 812, 0<<D, Line@880, 0<, 85, 6<<D, Line @880, 0<, 82, 0<<D, Line@880, 0<, 83.4, 6.5<<D, Line @880, 0<, 86.8, 5.7<<D, 8RGBColor@0,
0.500008, 0 D, Disk@810, 0<, 81, 2<D<, 8RGBColor@0.996109, 0.996109, 0.500008D,
Disk @810, 0<, 8.6, 1.5<D<, 8RGBColor@0,
0, 0.996109 D, Disk@85, 6<, 81.6, 1.3<D<, Arrow @812, 1.5<, 810, 1.5<D, Arrow@85, 6<,
q db
a
Trang 371.1.6 Programming
Mathematica not only is an interactive system but also allows one to
generate programs supporting scientific calculations By solving thefollowing mathematical conjecture, we simultaneously demonstrate the
creation of an interactive function in Mathematica The iteration of the
The sums in the representation of the polynomial extend across the range
0 < n < ¶ In the first step of the calculation, we introduce a list containing the initial conditions of the iteration Lists in Mathematica are
represented by a pair of braced brackets which contain the elements of thelist separated by commas To save the list for future use, we set the list
equal to the variable listf by
listf = 8Cos@xD, Sin@xD<
8Cos@xD, Sin@xD<
Trang 38The first iteration step in Equation (1.1.1) is executed by the sequence
AppendTo Alistf,
listf P1T IntegrateAi
k
jj cccccccccccccccc listf P2T cccccccc listf P1T y { zz 2 , x EE êê Simplify
8Cos@xD, Sin@xD, x Cos@xD + Sin@xD<
in which we append the result from an integration of the iteration formula
to listf by means of the function AppendTo[] The next step just changes
the indices of the iteration and is given by
AppendTo Alistf,
listf P2T IntegrateAi
k
jj cccccccccccccccc listf P3T cccccccc listf P2T y { zz 2 , x EE êê Simplify
9Cos@xD, Sin@xD, x Cos@xD + Sin@xD,
cccc1
Here, we increase the indices of the list elements in listf by one The next
interactive step results in
AppendTo Alistf,
listf P3T IntegrateAi
k
jj cccccccccccccccc listf P4T cccccccc listf P3T y { zz 2 , x EE êê Simplify
9Cos@xD, Sin@xD, x Cos@xD + Sin@xD,
Applying the function Plus[] to listf adds all elements of the list together,
resulting in the representation of the polynomial in the form
Trang 39poly = Apply@Plus, listfD êê Simplify
y{
zz Cos@xD + i
kjj2 + x 2 x5
ccccccccccc15
y{
and
Coefficient @poly, Sin@xDD
2+ x ccccccccccc2 x5
15
verifying the conjecture that the resulting function of the iteration is a
polynomial with coefficients Cos[x] and Sin[x] The disadvantage of this
calculation is that we need to repeat the iteration To avoid such repetition,
we define a procedural function which performs the repetition
automatically Function Iterate[] derives the polynomial up to an iteration
order n.
Trang 40Iterator @8expr1_, expr2_<D :=
Expand @expr1 Integrate@Hexpr2 ê expr1L^2, xDD
The second part extracts the last two elements from a list: