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.
Before discussing the C++ language in detail, we summarize its conceptualfoundations. Since C++ consistently adheres to a small number of basicprinciples, acquiring a working understanding of these greatly hastens learningof C++ syntax.
Overview of program structure
The smallest unit of a C++ program is a token, which is a letteror symbol that the compiler can process. Appropriate groups of tokens yieldwords. Of these, identifiers (variable names) formatomic (single-element) expressions.Operators combine expressions to form new expressions.Terminating a valid expression with a semicolon yields astatement, which is equivalent to a sentence. Ablock, which is analogous to a paragraph, unifies andisolates one or more statements from the remainder of the program.Control structures determine the program flow according tothe outcome of logical operations, while functions and possiblysubroutines modularize compound statements by associating alabel with a frequently occurring sequence of statements. Finally,classes and objects structure relatedvariables and functions into generalized arrays. These, like a chapter, describea single topic, namely the properties of a related group of objects.
Tokens, names and keywords
The C++ compiler processes source-code lines in order of appearance and textwithin a line from left to right. A program is read as a sequence of tokensseparated by non-printing whitespace characters, which includetabs, carriage returns and spaces. Valid tokens are a–z, A–Z, 0–9 and certainpunctuation characters. Upper- and lower-case letters represent different tokenssuch that myVariable and myvariable are unrelated names. A word is a sequence oftokens terminated by whitespace. A reserved keyword is a wordsuch as int or if for which the complier has a specialinterpretation.
A pointer variable like a reference or array variable stores a memory address; however, this address can be arbitrarily changed, enabling the contents of any accessible memory location to be addressed and manipulated directly. While enabling access to all available resources, new and subtle types of errors arise. For example, when a program requests additional memory during runtime from the operating system, the address of the starting location to the new, dynamically allocated variable is returned. Since the value stored in a preexisting compiler-allocated pointer variable can be altered, the running program can preserve the address passed back by the operating system. However, if the pointer variable was defined within an inner block, it will be destroyed when the block terminates. The location of the dynamically allocated memory is then lost and the memory cannot subsequently be accessed or later freed.
Introduction to pointers
A definition in C++ establishes the amount of memory space required for a variable and the interpretation of the value stored at this memory location. The value of a pointer variable is associated with the starting memory address of a variable of a specified type, i.e. the value of a pointer is a memory address. That is, a double pointer that stores a value such as 80000 interprets the 8-byte region from physical memory location 80000 to location 80007 as the storage location of a double variable. The amount of memory space reserved by any pointer variable equals the number of bits required to store a hardware memory address – on a 32-bit machine, an address requires 4 bytes so that applying the sizeof( )function to any pointer yields 4.
For small programs or rapid prototyping of ideas and methods, the commercialMATLAB® language, or its freeware alternatives, offers a practicalalternative to C++ or FORTRAN. In this book, the free GNU Octave implementationis discussed from a scientific programming perspective. After becoming familiarwith the central language constructs summarized below, the built-in Octave helpfacilities conveniently provide information on specialized, infrequentcommands.
Obtaining octave
The Windows and Mac installation packages for GNU Octave are currently located atoctave.sourceforge.net. Linux versions are available at the main Octave web sitewww.gnu.org/software/octave. When the program is installed, avariety of additional packages and the creation of a database of C++ componentsaccessible by the editor can be selected. Unless space is an issue, theseoptions should be chosen.
Command summary
(1) Running Octave. After clicking on the Octave icon, statements are entered interactivelyby typing into the resulting command window at the > prompt. An Octavesession is terminated by typing quit.
(2) System commands.To change from the startup directory (folder) to the directorythat either contains or will contain program files, type cd X:\dir1\dir2\ . . .\programDirectory, where X is the partition (logical drive) containing the desireddirectory and \dir1\dir2 . . . \programDirectory is an ordered sequence of thenames of the directories enclosing the directory, \programDirectory, in which theprogram is located. If one or more directory names contain spaces, the entire expressioncontaining these names must be surrounded by double apostrophes ("), e.g.cd "X:\My Documents". Representative operating-system commands that can beissued from the Octave prompt include mkdir directoryName, which creates thedirectory directoryName, rmdir directoryName, which removes this directory, dir or Is which display the contents of a directory, .., which moves to one directoryhigher in the directory tree, ., which represents the current directory, rename file1.1file2.2, which renames the file file1.1 to the name file2.2, and copy, which similarlycopies a file.
The ability to summarise data, compare models and apply computer-based analysis tools are vital skills necessary for studying and working in the physical sciences. This textbook supports undergraduate students as they develop and enhance these skills. Introducing data analysis techniques, this textbook pays particular attention to the internationally recognised guidelines for calculating and expressing measurement uncertainty. This new edition has been revised to incorporate Excel® 2010. It also provides a practical approach to fitting models to data using non-linear least squares, a powerful technique which can be applied to many types of model. Worked examples using actual experimental data help students understand how the calculations apply to real situations. Over 200 in-text exercises and end-of-chapter problems give students the opportunity to use the techniques themselves and gain confidence in applying them. Answers to the exercises and problems are given at the end of the book.
In chapter 3 we considered the normal distribution largely due to its similarityto the distribution of data observed in many experiments involving repeatmeasurements of a quantity. In particular, the normal distribution is useful fordescribing the spread of values when continuous quantities such as temperatureor time interval are measured.
Another important category of experiment involves counting. As examples, we maycount the number of electrons scattered by a gas, the number of charge carriersthermally generated in an electronic device, or the number of beta particlesemitted by a radioactive source. In these situations, distributions thatdescribe discrete quantities must be considered. In this chapter we consider twosuch distributions important in science: the binomial and Poissondistributions.
The binomial distribution
One type of experiment involving discrete variables entails removing an objectfrom a population and classifying that object in one of a finite number of ways.For example, we might test an electrical component and classify it‘within specification’ or ‘outside specification’.Owing to the underlying (and possibly unknown) processes causing components tofail to meet the specification, we can only give a probability that anyparticular component tested will satisfy the specification. Whenn objects are removed from a population and tested, or whena coin is tossed n times, we speak of performingn trials. The result of a test (e.g. ‘pass’)or the result of a coin toss (e.g. ‘head’) is referred to as anoutcome.
I thank Cambridge University Press, and in particular Simon Capelin, for the opportunity to revisit Data Analysis with Excel. I have revised sections of the book to include topics of contemporary relevance to undergraduate students, particularly in the area of uncertainty in measurement. I hope the book will continue to assist in developing the quantitative skills of students destined to graduate in the physical sciences. There is little doubt that the demand for such skills will continue to grow in society in general and particularly within industry, research, education and commerce.
This edition builds on the first with a new chapter added and others undergoing major or minor modifications (for example, to remedy mistakes, update references or include more end of chapter exercises).
We may believe that the ‘laws of chance’ that apply when tossing a coin or rolling dice have little to do with experiments carried out in a laboratory. Rolling dice and tossing coins are the stuff of games. Surely, well planned and executed experiments provide precise and reliable data, immune from the laws of chance. Not so. Chance, or what we refer to more formally as probability, has rather a large role to play in every experiment. This is true whether an experiment involves counting the number of beta particles detected by nuclear counting apparatus in one minute, measuring the time a ball takes to fall a distance through a liquid or determining the values of resistance of 100 resistors supplied by a component manufacturer. Because it is not possible to predict with certainty what value will emerge when a measurement is made of a quantity, say of the time for a ball to fall a fixed distance through liquid, we are in a similar position to a person throwing several dice, who cannot know in advance which numbers will appear ‘face up’. If we are not to give up in frustration at our inability to discover the ‘exact’ value of a quantity experimentally, we need to find out more about probability and how it can assist rather than hamper our experimental studies.
In many situations a characteristic pattern or distribution emerges in data gathered when repeat measurements are made of a quantity. A distribution of values indicates that there is a probability associated with the occurrence of any particular value. Related to any distribution of ‘real’ data there is a probability distribution which allows us to calculate the probability of the occurrence of any particular value. Real probability distributions can often be approximated by a ‘theoretical’ probability distribution. Though it is possible to devise many theoretical probability distributions, it is the so called ‘normal’ probability distribution (also referred to as the Gaussian distribution) that is most widely used. This is because histograms of data obtained in many experiments have shapes that are very similar to that of the normal distribution. An attraction of the normal and other distributions is that they provide a way of describing data in a quantitative manner which complements and extends visual representations of data such as the histogram. Using the properties of the normal distribution we are usually able to summarise a whole data set, which may consist of many values, by one or two carefully chosen numbers.