To save content items to your account,
please confirm that you agree to abide by our usage policies.
If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account.
Find out more about saving content to .
To save content items to your Kindle, first ensure no-reply@cambridge.org
is added to your Approved Personal Document E-mail List under your Personal Document Settings
on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part
of your Kindle email address below.
Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations.
‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi.
‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
In chapters 2 and 5 we discussed how to find stationary values of functions of a single variable f(x), of several variables f(x, y, …) and of constrained variables, where x, y, … are subject to the n constraints gi(x, y, …) = 0, i = 1, 2, …, n. In all these cases the forms of the functions f and gi were known, and the problem was one of finding the appropriate values of the variables x, y etc.
We now turn to a different kind of problem in which we are interested in bringing about a particular condition for a given expression (usually maximising or minimising it) by varying the functions on which the expression depends. For instance, we might want to know in what shape a fixed length of rope should be arranged so as to enclose the largest possible area, or in what shape it will hang when suspended under gravity from two fixed points. In each case we are concerned with a general maximisation or minimisation criterion by which the function y(x) that satisfies the given problem may be found.
The calculus of variations provides a method for finding the function y(x). The problem must first be expressed in a mathematical form, and the form most commonly applicable to such problems is an integral. In each of the above questions, the quantity that has to be maximised or minimised by an appropriate choice of the function y(x) may be expressed as an integral involving y(x) and the variables describing the geometry of the situation.
Since the publication of the first edition of this book, both through teaching the material it covers and as a result of receiving helpful comments from colleagues, we have become aware of the desirability of changes in a number of areas. The most important of these is that the mathematical preparation of current senior college and university entrants is now less thorough than it used to be. To match this, we decided to include a preliminary chapter covering areas such as polynomial equations, trigonometric identities, coordinate geometry, partial fractions, binomial expansions, necessary and sufficient condition and proof by induction and contradiction.
Whilst the general level of what is included in this second edition has not been raised, some areas have been expanded to take in topics we now feel were not adequately covered in the first. In particular, increased attention has been given to non-square sets of simultaneous linear equations and their associated matrices. We hope that this more extended treatment, together with the inclusion of singular value matrix decomposition, will make the material of more practical use to engineering students. In the same spirit, an elementary treatment of linear recurrence relations has been included. The topic of normal modes has been given a small chapter of its own, though the links to matrices on the one hand, and to representation theory on the other, have not been lost.
It may seem obvious that the quantitative description of physical processes cannot depend on the coordinate system in which they are represented. However, we may turn this argument around: since physical results must indeed be independent of the choice of coordinate system, what does this imply about the nature of the quantities involved in the description of physical processes? The study of these implications and of the classification of physical quantities by means of them forms the content of the present chapter.
Although the concepts presented here may be applied, with little modification, to more abstract spaces (most notably the four-dimensional space–time of special or general relativity), we shall restrict our attention to our familiar threedimensional Euclidean space. This removes the need to discuss the properties of differentiable manifolds and their tangent and dual spaces. The reader who is interested in these more technical aspects of tensor calculus in general spaces, and in particular their application to general relativity, should consult one of the many excellent textbooks on the subject.
Before the presentation of the main development of the subject, we begin by introducing the summation convention, which will prove very useful in writing tensor equations in a more compact form. We then review the effects of a change of basis in a vector space; such spaces were discussed in chapter 8. This is followed by an investigation of the rotation of Cartesian coordinate systems, and finally we broaden our discussion to include more general coordinate systems and transformations.
In science as well as in everyday life we constantly encounter situations and processes which are stochastic in nature, i.e., we cannot predict from the observation of one event how the next event with the same initial starting conditions will come out. Say you have a coin which you throw in the air. The only prediction about the outcome you can make is to say that you have a 50% chance that the coin will land on its tail. After recording the first event, which was a head, you toss it up again. The chance that the coin will land on its tail is still 50%. As every statistics teacher has taught you, you need to execute these throws a large number of times, to get an accurate distribution. The same is true when you roll a die. The only prediction you can make is that in a large number of throws each number has a probability of 1/6. Now assume that you have 10 dice, and you are to record all distributions in 10,000 throws. Of course probability theory will predict the outcome for any combination you wish to single out; for example, the chances to get all “ls” in one throw (1/6). However, actually trying to do this experiment would keep you busy for quite some time (and in addition you would not learn anything new).
Before we start we need to introduce a few concepts of computers and the interaction between you, the user, and the machine. This will help you decide when to write a program for solving a physics or science problem and when it is much easier or faster to use a piece of paper and a pocket calculator. In thinking about computers, remember there is a distinction between hardware and software. Software is divided into the operating system and your particular application, like a spreadsheet, word-processor or a high level language. In this book we will spend most of the time in dealing with issues relevant to physics and the algorithms used to solve problems. However, in order to make this as productive as possible, we will start off with a short description of the hardware and then some discussion of the operating system.
Basic computer hardware
Apart from huge parallel supercomputers, all workstations you can buy today are organized in a similar way (Figure 2.1).
The heart of the computer is the CPU (Central Processing Unit) controlling everything in your workstation. Any disk I/O (Input/Output) or computational task is handled by the CPU. The speed at which this chip can execute an instruction is measured in Hz (cycles per second) at several GHz. The CPU needs places to store data and instructions. There are typically four levels of memory available: level I cache, level II cache, RAM (Random Access Memory) and swap space, the last being on the hard disk.
Root is a very powerful data analysis package which was developed and written at CERN, the European high energy accelerator lab. It consists of a library of C++ classes and functions for histogramming, data manipulation (like fitting and data reduction) and storage tools. There are two ways to use ROOT. One way is by calling the appropriate functions from your own program. The second way relies on a C++ interpreter and a graphical user interface, allowing you to display and manipulate data interactively. Originally written for high energy physics, it is today also widely used in other fields, including astrophysics, neural network applications, and financial institutions on Wall Street.
The ROOT basics
ROOT in the word of its authors is an “object oriented framework” [11]. Instead of having to write your own graphics routines, or modify existing programs to suit your needs, a framework provides you with functions and routines which are already well tested. ROOT, having been developed by physicists for physics problems, gives you a large class of routines which you can just use “out of the box.”
One of the main advantages of ROOT is that it is running and supported on all the major UNIX platforms, as well as on Windows XP and MacOS. This widespread availability makes it the perfect choice, reducing the chances of having to learn a new package every time you change computers.
Before we can discuss how to call FORTRAN functions from C++, we need first to look at some of the differences.
The most important difference is that FORTRAN passes variables by reference, while C++, like C, passes by value. This in turn means that any FORTRAN routine expects to get a reference, so you have to make sure your program passes the variables appropriately.
When you use arrays in your program, you have to take into account that the first array element in FORTRAN is a(1), while in C++ it would be a[0]. Multi-dimensional arrays are stored differently in memory. Array A(3,5) in FORTRAN would be A(1,1), A(2,1), A(3,1), A(1,2), while in C++ the corresponding arrangement would be A(0,0), A(0,1), A(0,2), A(0,3), A(0,4), A(1,0) and so on.
C++ is a strongly typed language; if you do not define a variable your program will not compile. FORTRAN has by default an implicit type convention: any variable which starts with letters i through n is an integer, while any other variable is a real variable. Unless the programmer has used the “implicit none” statement any FORTRAN compiler will adhere to the standards.
FORTRAN is case insensitive, while C++ clearly distinguishes between Dummy and dummy.
We will try to jump-start you into the Linux environment. The first thing you have to do is log into the system. Since Linux is a real multi-user system, the interaction between you and the computer might be different than what you are used to from a Microsoft or Macintosh environment. You could be either at the computer console or at a terminal, which is connected via a network to the computer. In either way, you will see a Windows-like screen which will display a login screen, asking you for the username and the password. Assuming that your system manager has set you up already, you will type in both, and as long as you did not mistype anything you should now be in the computer. In case you made a mistake in typing in either of the two items, the computer will not let you in. (Note that Linux is case sensitive, so Emma is not the same as emma.) Depending on the setup of your computer, you will now be faced with a graphical user interface (GUI), the most common of these being either KDE or Gnome. Click on the small icon which resembles a terminal. This will bring a new window, which lets you type in commands, somewhat like the command icon in DOS. If this is the first time you have logged into this account, you should change your password, especially if your system administrator has assigned one to you.
Over the last few decades, computers have become part of everyday life. Once the domain of science and business, today almost every home has a personal computer (PC), and children grow up learning expressions like “hardware,” “software,” and “IRQ.” However, teaching computational techniques to undergraduates is just starting to become part of the science curriculum. Computational skills are essential to prepare students both for graduate school and for today's work environment.
Physics is a corner-stone of every technological field. When you have a solid understanding of physics, and the computational know-how to calculate solutions to complex problems, success is sure to follow you in the high-tech environment of the twenty-first century.
What is computational physics?
Computational physics provides a means to solve complex numerical problems. In itself it will not give any insight into a problem (after all, a computer is only as intelligent as its user), but it will enable you to attack problems which otherwise might not be solvable. Recall your first physics course. A typical introductory physics problem is to calculate the motion of a cannon ball in two dimensions. This problem is always treated without air resistance. One of the difficulties of physics is that the moment one goes away from such an idealized system, the task rapidly becomes rather complicated. If we want to calculate the solution with real-world elements (e.g., drag), things become rather difficult.
Computers are one of the most important tools in any field of science and especially in physics. A student in an undergraduate lab will appreciate the help of a computer in calculating a result from a series of measurements. The more advanced researcher will use them for tasks like simulating an experiment, or solving complex systems of equations. Physics is deeply connected to mathematics and requires a lot of calculational skills. If one is only interested in a conceptual understanding of the field, or an estimate of the outcome of an experiment, simple calculus will probably suffice. We can solve the problem of a cannon ball without air resistance or Coriolis force with very elementary math, but once we include these effects, the solution becomes quite a bit more complicated. Physics, being an experimental science, also requires that the measured results are statistically significant, meaning we have to repeat an experiment several times, necessitating the same calculation over and over again and comparing the results. This then leads to the question of how to present your results. It is much easier to determine the compatibility of data points from a graph, rather than to try to compare say 1000 numbers with each other and determine whether there is a significant deviation. From this it is clear that the computer should not only “crunch numbers,” but should also be able to display the results graphically.
In the past, the dominant computer language for scientific computing was FORTRAN. This created a wealth of libraries with well tested routines, which address almost all numerical problems covered in this book. However, using these libraries “out of the box,” without understanding their limitations and algorithms, is bound to get you into trouble one day. Because we are using C++, you will want to know how to call these FORTRAN routines from a C++ program. This will allow you to use these routines without having to rewrite them in C++.
LAPACK
LAPACK: Linear Algebra PACKage.
LAPACK is written in Fortran77 and provides routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems. The associated matrix factorizations (LU, Cholesky, QR, SVD, Schur, generalized Schur) are also provided, as are related computations such as reordering of the Schur factorizations and estimating condition numbers. Dense and banded matrices are handled, but not general sparse matrices. In all areas, similar functionality is provided for real and complex matrices, in both single and double precision.
From the Website http://www.netlib.org/lapack/index.html, where the whole package can be downloaded. There is now also a C++ version available, called LAPACK++.
SLATEC
SLATEC is another very useful package which contains general purpose mathematical and statistical programs. You will find this at http://www.netlib.org/slatec/index.html.
Where to obtain ROOT
An important aspect about ROOT to remember is the developer's philosophy: “Release early and release often.”