This section of these pages is intended mainly for the modules 2NP and 2NP3 taken in the School of Mathematics, University of Birmingham, by second year students. It is available here for other students and anyone else that might be interested to look at at their own risk. There is no waranty or guarantee of fitness for any purpose. These notes have been developed rather intensively over a period since 2015. Please keep returning here for more up-to-date versions. In particular answers to various exercises may not be provided here (especially if they are assessed exercises for current students). Current students following these modules will also have a set of pages for assessments and feedback delivered via Canvas. These (non-Canvas) pages are intended to take the place of a "course textbook" to support the learning.

It is assumed here that you have some experience with using a computer and in particular some programming experience, though not necessarily in C or C++. (First years in Mathematics at Birmingham learn the basics of the language Lua. See http://web.mat.bham.ac.uk/R.W.Kaye/year1prog/.) However, if you are careful and methodical you should be able to follow these pages from scratch without prior programming experience.

The syllabus for the module (and objectives for these notes) is as follows.

- Mathematical and numerical programming in C++.
- The run-time of a program, and $O\left(f\left(n\right)\right)$ notation, with simple examples.
- The way real numbers are represented on the computer by
`double`and`float`, and an introduction to error analysis. - A number of useful algorithms, taken from numerical analysis and discrete maths including sorting algorithms, and the methods to analyse and apply them properly.

With the possible exception of some of the algorithms in the last
bullet point. this is all material that I would expect any
*mathematician* using a computer will be expected to know. (Some
topics here are not even typically taught to computer science
students!) The official syllabus for the 2NP module is very full, and
(I think) unreasonably so. So the focus of the module will be on the
first three bullet points and as many of the "useful algorithms" that
we can cover in the time available.

These pages are intended to get you started using C++ for
traditional numerical work. For various reasons (speed of execution,
available packages, standardised syntax) C++ is a superior language
for tranditional mathematical number-crunching to some of the obvious
alternatives such as FORTRAN and C. But this kind of traditional work
does not require detailed knowledge of some of C++'s best features
such as classes and templates and these aspects of C++ are not covered
here. A number of other important C++ topics, such as pointers,
structs, namespaces and exceptions are also omitted for the same
reason. On the other hand we *do* try to push the reader into good
C++ style in preparation for all this other good stuff, and we *do not*
encourage those "dirty shortcuts" from C, as is (sadly) all too
common.

**Background: admin and other stuff**

- Home page and copyright notice
- Contents (this page)
- Installation instructions (for using your own computer)
- Use of the Code::Blocks IDE

**From register machines to C++**

This section is intended to get you started with C++ via a small
(and very interesting) machine model for the computer called a
*register machine*. By the end of this section you will have a much
clearer idea of what a computer program does, how the computer follows
the instructions in the program, how to analyse the time taken by a program,
and how numbers are stored in the computer. You will also have a very
useful start in how to write C++ code.

- Register machines
- Compiling and running register machines
- Register machine examples
- More on register machines
- Binary notation
- The O() notation
- More register machines examples and exercises
- Register machines in C++
- Starting C++
- C++ examples: Sequences
- Floating point numbers in C++

**Programming in C++**

This section provides much more detail on C++ and is intended to
get you proficient with those parts of C++ that you will need for
numerical and related work in mathematics. If you have been following
the previous section closely, most of the first few pages here should
be mostly revision, and the first important new material starts with
*functions*.

- Why must we be so fussy?
- The first program
- Compiling C++
- Simple input and output
- Conditionals and loops
- Introduction to functions
- Examples of functions: x to the y mod m
- Types
- Variables
- Introduction to expressions
- Arrays and vectors
- Good programming style
- Summary of good and tricky points of C++
- Analogies between programs and proofs

**C++ reference and further comments**

This section provides much more detail on C++ and is intended to provide some reference for specific aspects of the language.

- A detailed look at programming constructs
- A detailed look at expressions
- A detailed look at functions
- A detailed look at double values
- Use of complex values

**Introduction to numerical work in C++**

This section provides much more detail on C++ and is intended to get you proficient with those parts of C++ that you will need for numerical and related work in mathematics.

- On errors
- Solving quadratics using the formula
- Solving cubics by the bisection method
- The Newton-Raphson method
- Interpolation and extrapolation
- Functionals and numerical differentiation

**Some miniprojects**

This section provides information on some longer examples and interesting C++ miniprojects

- Some examples of use of vectors in C++
- More examples and exercises using vectors for set theory
- Graph connectivity, main part
- Graph connectivity, supplement
- Array sorting and run-time
- Other sorting algorithms
- More on sorting algorithms
- Numerical integration
- Initial value problems

All code and content here may be copied as often as you like under the terms of the GNU General Public Licence and/or the GNU Free Documentation Licence. (In reading these texts, the words "licence" and "license" are to be taken to be synonymous.) This means that any derivative work, if distributed further and not for your own private use, MUST be issued with a similar licence.

All content is copyright by Richard Kaye, http://web.mat.bham.ac.uk/R.W.Kaye/ 2018.