Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed typos in several notebooks #27

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions 02 Control statements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The meaning of the statement becomes clear if read it left-to-right.\n",
"The meaning of the statement becomes clear if read from left-to-right.\n",
"\n",
"Below is a very simple example that, given the current time of day reports \n",
"\n",
Expand Down Expand Up @@ -815,7 +815,7 @@
"source": [
"since we might not know beforehand how many steps are required before `x > 0.001` becomes false. \n",
"\n",
"If $x \\ge 1$, the above would lead to an infinite loop. To make a code robust, it would be good practice to check that $x < 1$ before entering the `while` loop."
"If $x \\ge 1$, the above would lead to an infinite loop. To make the code robust, it would be good practice to check that $x < 1$ before entering the `while` loop."
]
},
{
Expand Down
14 changes: 7 additions & 7 deletions 03 Types, type conversions and floating point arithmetic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"source": [
"# Introduction\n",
"\n",
"We have thus far avoided discussing directly *types*. The '*type*' is the type of object that a variable is associated with. This affects how a computer stores the object in memory, and how operations, such as multiplication and division, are performed.\n",
"We have thus far avoided discussing directly *types*. The '*type*' is the kind of object that a variable is associated with. This affects how a computer stores the object in memory, and how operations, such as multiplication and division, are performed.\n",
"\n",
"In *statically typed* languages, like C and C++, types come up from the very beginning because \n",
"you usually need to specify types explicitly in your programs. Python is a *dynamically typed* language, which means types are deduced when a program is run. This is why we have been able to postpone the discussion until now.\n",
"It is important to have a basic understanding of types, and how types can affect how your programs behave. One can go very deep into this topic, especially for numerical computations, but we will cover the general concept from a high level, \n",
"show some examples, and highlight some potential pitfalls for engineering computations. \n",
"show some examples, and highlight some potential pitfalls in engineering computations. \n",
"\n",
"This is a dry topic - it contains important background information that you need to know for later, so hang in there. The below account highlights what can go wrong without an awareness of types and how computers process numbers."
]
Expand Down Expand Up @@ -255,7 +255,7 @@
"# Get first six characters, print and check type\n",
"s3 = my_string[0:6]\n",
"print(s3)\n",
"print(type(s2))\n",
"print(type(s3))\n",
"\n",
"# Get last four characters and print\n",
"s3 = my_string[-4:]\n",
Expand Down Expand Up @@ -522,7 +522,7 @@
"source": [
"### Floats\n",
"\n",
"We can declare a float by adding a decimal point:"
"We can declare a variable as a float by adding a decimal point:"
]
},
{
Expand Down Expand Up @@ -1186,7 +1186,7 @@
"earlier. However, this was a little misleading because computers do not use base 10\n",
"to store the significand and the exponent, but base 2. \n",
"\n",
"When using the familiar base 10, we cannot represent $1/3$ exactly as a decimal. If we liked using base 3 (ternary numeral system) for our mental arithmetic (which we really don't), we could represent $1/3$ exactly. However, fractions that are simple to represent exactly in base 10 might not be representable in another base.\n",
"When using the familiar base 10, we cannot represent $1/3$ exactly as a decimal. If we liked using base 3 (ternary numeral system) for our mental arithmetic (which we really don't), we could represent $1/3$ exactly. However, fractions that are simple to represent exactly in base 10 might not be exactly representable in another base.\n",
"A consequence is that fractions that are simple in base 10 cannot necessarily be represented exactly by computers using binary.\n",
"\n",
"A classic example is $1/10 = 0.1$. This simple number cannot be represented exactly in\n",
Expand Down Expand Up @@ -1283,7 +1283,7 @@
"If $x = 0.1$, we can write\n",
"\n",
"$$\n",
"x = 11x - 1\n",
"x = 1.1x - 1\n",
"$$\n",
"\n",
"Now, starting with $x = 0.1$ we evaluate the right-hand side to get a 'new' $x$, and use this new $x$ to then evaluate the right-hand side again. The arithmetic is trivial: $x$ should remain equal to $0.1$.\n",
Expand Down Expand Up @@ -1528,7 +1528,7 @@
"- The size of an integer that a computer can store is determined by the number of bits used to represent the \n",
" integer.\n",
"- Computers do not perform exact arithmetic with non-integer numbers. This does not usually cause a problem, but \n",
" it can in cases. Problems can often be avoided with careful programming.\n",
" it can in some cases. Problems can often be avoided with careful programming.\n",
"- Be thoughtful when converting between types - undesirable consequences can follow when careless with \n",
" conversions."
]
Expand Down
4 changes: 2 additions & 2 deletions 04 Functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"source": [
"# Purpose\n",
"\n",
"Functions allow computer code to be re-used multiple times with different input data. It is good to re-use code as much as possible because we then focus testing and debugging efforts, and maybe also optimisations, on small pieces of code that are then re-used. The more code that is written, the less frequently sections of code are used, and as a consequence the greater the likelihood of errors.\n",
"Functions allow computer code to be re-used multiple times with different input data. It is good to re-use code as much as possible because we then focus our testing and debugging efforts, and maybe also optimisations, on small pieces of code that are then re-used. The more code that is written, the less frequently sections of code are used, and as a consequence the greater the likelihood of errors.\n",
"\n",
"Functions can also enhance the readability of a program, and make it easier to collaborate with others. Functions allow us to focus on *what* a program does at a high level \n",
"rather than the details of *how* it does it. Low-level implementation details are *encapsulated* in functions. To understand at a high level what a program does, we usually just need to know what data is passed into a function and what the function returns. It is not necessary to know the precise details of how a function is implemented to grasp the structure of a program and how it works. For example, we might need to know that a function computes and returns $\\sin(x)$; we don't usually need to know *how* it computes sine.\n",
Expand Down Expand Up @@ -178,7 +178,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Using a function, we did not have to duplicate the `if-elif-else` statement inside each loop\n",
"Using a function, we did not have to duplicate the `if-elif-else` statement inside each loop,\n",
"we re-used it.\n",
"With a function we only have to change the way in which we process the number `x` in one place."
]
Expand Down
6 changes: 3 additions & 3 deletions 05 Library functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"# Introduction\n",
"\n",
"A feature of modern programming languages is an extensive library of standard functions. This means that we can make use of standard, well-tested and optimised functions\n",
"for performing common tasks rather than writing our own. This makes our programs shorter and of higher quality, and in most cases faster.\n",
"for performing common tasks rather than writing our own. This makes our programs shorter, of higher quality, and in most cases faster.\n",
"\n",
"\n",
"\n",
Expand Down Expand Up @@ -174,7 +174,7 @@
"metadata": {},
"source": [
"Renaming functions at import can be helpful to keep code short, and we will see below it can be useful for switching between different functions.\n",
"However the above choice of name is very poor practice - the name '`some_math_function`' is not descriptive.\n",
"However, the above choice of name is very poor practice - the name '`some_math_function`' is not descriptive.\n",
"Below is a more sensible example."
]
},
Expand Down Expand Up @@ -477,7 +477,7 @@
"source": [
"We see from the output that three different processes have worked on our problem - one for each sorting task.\n",
"\n",
"We use parallel processing the make computations faster. Let's time our computation using different numbers\n",
"We use parallel processing to make computations faster. Let's time our computation using different numbers\n",
"of processes to see how it affects performance. \n",
"To perform the timing, we first encapsulate our problem in a function:"
]
Expand Down
12 changes: 6 additions & 6 deletions 07 Numerical computation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The function `linspace` creates an array with prescribed start and end values (both are included), and a prescribed number on values, all equally spaced:"
"The function `linspace` creates an array with prescribed start and end values (both are included), and a prescribed number of values, all equally spaced:"
]
},
{
Expand Down Expand Up @@ -420,7 +420,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"and multiplication of components by a scalar,"
"and multiplication of each element by a scalar,"
]
},
{
Expand All @@ -445,7 +445,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"and raising components to a power:"
"and raising each element to a power:"
]
},
{
Expand Down Expand Up @@ -558,7 +558,7 @@
"followed by taking the square root.\n",
"To compute the norm, we could loop/iterate over the entries of the vector and sum the square of each entry, and then take the square root of the result.\n",
"\n",
"We will evaluate the norm using two methods for computing the norm of an array of length 10 million to compare their performance. We first create a vector with 10 million random entries, using NumPy:"
"We will use two methods for computing the norm of an array of length 10 million to compare their performance. We first create a vector with 10 million random entries, using NumPy:"
]
},
{
Expand Down Expand Up @@ -613,8 +613,8 @@
"source": [
"The time output of interest is '`Wall time`'.\n",
"\n",
"> The details of how `%time` works are not important for this course. We use it as a compact and covenient tool to \n",
"> measure how much time a command takes to execute.\n",
"The details of how `%time` works are not important for this course. We use it as a compact and covenient tool to \n",
"measure how much time a command takes to execute.\n",
"\n",
"We now perform the same operation with our own function for computing the norm:"
]
Expand Down
24 changes: 12 additions & 12 deletions 08 Plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"We will use the tools presented in this notebook to visualise results in subsequent notebooks.\n",
"\n",
"> This is a long activity - this a reflection of the importance of plotting. The next activity\n",
"> is shorter in compensation.\n",
"is shorter in compensation.\n",
"\n",
"> Some exercises in this notebook are challenging. Use the forum to get help.\n",
"\n",
Expand Down Expand Up @@ -67,7 +67,7 @@
"```\n",
"\n",
"Below we install the `quandl` package which will be used further down to fetch and plot stock prices.\n",
"You can skip over the details, and it should just work. The code is a little complex because it is designed work for a range of different Python environments. If you get an error message in the following code blocks, send a message with the error to the Moodle forum.\n",
"You can skip over the details, and it should just work. The code is a little complex because it is designed to work for a range of different Python environments. If you get an error message in the following code blocks, send a message with the error to the Moodle forum.\n",
"\n",
"To install the `quandl` package:"
]
Expand All @@ -81,7 +81,7 @@
"import sys\n",
"if 'conda' in sys.version: # Install using conda if we're using Anaconda Python\n",
" !conda install -yc conda-forge quandl\n",
"else: # Install using pip on others systems\n",
"else: # Install using pip on other systems\n",
" try:\n",
" !{sys.executable} -m pip -q install quandl --user # Try to install in userspace\n",
" import quandl\n",
Expand All @@ -102,7 +102,7 @@
"metadata": {},
"source": [
"We will be using the `ipywidgets` module for interactive plots. It has already been configured for you on\n",
"https://notebooks.azure.com/, so the below is necessary only if using other environments."
"https://notebooks.azure.com/, so the code below is necessary only if using other environments."
]
},
{
Expand Down Expand Up @@ -204,7 +204,7 @@
"8 | 13\n",
"10 | 1\n",
"\n",
"we want to create a line plot of $x$-values (horizontal axis) against the $f$ values (vertical axis).\n",
"we want to create a line plot of $f$ values (vertical axis) against the $x$-values (horizontal axis).\n",
"\n",
"We first create a list of `x` values and a list of `f` values:"
]
Expand Down Expand Up @@ -279,7 +279,7 @@
"# Attach labels and title (using LaTeX syntax)\n",
"plt.xlabel('$x$')\n",
"plt.ylabel('$f$')\n",
"plt.title(\"Simple plot of $x$ vs $f$\")\n",
"plt.title(\"Simple plot of $f$ vs $x$\")\n",
"plt.show()"
]
},
Expand All @@ -288,7 +288,7 @@
"metadata": {},
"source": [
"To change the colour of the line to red and use crosses at the data points, and to save the\n",
"plot to the file `my-plot.png`, we can do the following:"
"plot to the file `my-plot.pdf`, we can do the following:"
]
},
{
Expand Down Expand Up @@ -386,7 +386,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To evaluate $\\sin(x)$ for each value in the array `x`, we use the NumPy `sin` function, which can be applied entry-wise to `x`:"
"To evaluate $\\sin(x)$ for each value in the array `x`, we use the NumPy `sin` function, which can be applied element-wise to `x`:"
]
},
{
Expand Down Expand Up @@ -718,7 +718,7 @@
"# Plot normed histogram of data\n",
"n, bins, patches = plt.hist(x, 20, normed=1.0, facecolor='green', alpha=0.75);\n",
"\n",
"# Create array of 100 equally spaces points, stating from the first value in the bins\n",
"# Create array of 100 equally spaced points, starting from the first value in the bins\n",
"# through to the last values in the bins\n",
"xf = np.linspace(bins[0], bins[-1], 100)\n",
"\n",
Expand Down Expand Up @@ -892,10 +892,10 @@
"metadata": {},
"source": [
"(Remember, to get $\\omega$ and $\\alpha$ use `\\omega` + `Tab` key and `\\alpha` + `Tab` key.)\n",
"We have used default function arguments - these will be the initial parameters for out interactive plot.\n",
"We have used default function arguments - these will be the initial parameters for our interactive plot.\n",
"\n",
"Next, we use the `interact` function, passing to it the name of our function that does the plotting \n",
"(`plot` in this case), and a tuple for each parameters:"
"(`plot` in this case), and a tuple for each parameter:"
]
},
{
Expand Down Expand Up @@ -1178,7 +1178,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The below plots the function $f(x, y)$ in three-dimensions:"
"The code below plots the function $f(x, y)$ in three-dimensions:"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions 10 Algorithms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"## Characterising algorithms\n",
"\n",
"There is usually more than one way to solve a problem, hence there will\n",
"usually be more than one algorithm to solve a given problem. Some algorithms may be fast but\n",
"usually be more than one algorithm that can solve a given problem. Some algorithms may be fast but\n",
"inaccurate, others slow and accurate; some can be fast but use a lot of memory, while others may be \n",
"low-memory but slower. Some will be simple to program, others much harder.\n",
"We will look more at characterising the performance of algorithms in the next notebook on \n",
Expand Down Expand Up @@ -135,7 +135,7 @@
"source": [
"## Linear search\n",
"\n",
"The simplest search is linear search, where we iterate over all entries in a list/tuple/dictionary, etc, and check for the value(s) we are looking for. Here is an example of searching if a given colour is in a list:"
"The simplest search is linear search, where we iterate over all entries in a list/tuple/dictionary, etc, and check for the value(s) we are looking for. Here is an example of searching for a given colour in a list:"
]
},
{
Expand Down Expand Up @@ -486,7 +486,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We do not want to focus on details of the quicksort algorithm, but do wish to highlight the close resemblance between the pseudocode and the Python implementation.\n",
"We do not want to focus on the details of the quicksort algorithm, but do wish to highlight the close resemblance between the pseudocode and the Python implementation.\n",
"\n",
"We now test the implementation for an array of random numbers:"
]
Expand Down
6 changes: 3 additions & 3 deletions 11 Complexity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
"x = np.arange(N[-1])\n",
"x = np.sort(x)\n",
"\n",
"# Initlise an empty array to capture time taken\n",
"# Initialise an empty array to capture time taken\n",
"times = []\n",
"\n",
"# Time search for different problem sizes\n",
Expand Down Expand Up @@ -815,7 +815,7 @@
"plt.loglog(N, 1e-6*N*np.log(N), '--', label=r'$O(n\\log n)$')\n",
"\n",
"# Show reference line of O(n^2)\n",
"plt.loglog(N, 1e-6*N**2, '--', label=r'$O(n^2$)')\n",
"plt.loglog(N, 1e-6*N**2, '-.', label=r'$O(n^2$)')\n",
"\n",
"# Add labels\n",
"plt.xlabel('$n$')\n",
Expand Down Expand Up @@ -906,7 +906,7 @@
"\n",
"# Show reference lines of O(n*log(n)) and O(n^2)\n",
"plt.loglog(N, 1e-6*N*np.log(N), '--', label=r'$O(n\\log n)$')\n",
"plt.loglog(N, 1e-6*N**2, '--', label=r'$O(n^2$)')\n",
"plt.loglog(N, 1e-6*N**2, '-.', label=r'$O(n^2$)')\n",
"\n",
"# Show legend\n",
"plt.legend(loc=0);\n",
Expand Down
10 changes: 5 additions & 5 deletions 12 Object-oriented design.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Methods are functions, and as functions can take arguments. For example, we can use the method `sort` to sort the rows of an array: "
"Methods are functions, and as functions they can take arguments. For example, we can use the method `sort` to sort the rows of an array: "
]
},
{
Expand Down Expand Up @@ -499,7 +499,7 @@
"outputs": [],
"source": [
"class crazynumber:\n",
" \"A crazy number class that switches the mutliplcation and division operations\"\n",
" \"A crazy number class that switches the mutliplication and division operations\"\n",
" \n",
" # Initialiser\n",
" def __init__(self, x):\n",
Expand All @@ -523,7 +523,7 @@
"metadata": {},
"source": [
"> *Note:* the method names `__mul__`, ` __truediv__`, `__repr__`, etc, should not be called directly. They \n",
"> are mapped by Python to operators (`*` and `/` in the first two cases). The method `__repr__` is called behind the scenes when using `print`.\n",
"are mapped by Python to operators (`*` and `/` in the first two cases). The method `__repr__` is called behind the scenes when using `print`.\n",
"\n",
"We now create two `crazynumber` objects:"
]
Expand Down Expand Up @@ -605,7 +605,7 @@
"we might have a `StudentEntry` class, and then have a list with a `StudentEntry` object for each student.\n",
"The built-in sort functions cannot know how we want to sort our list.\n",
"\n",
"Another case is if we have a list of numbers, and we we want to sort according to a custom rule?\n",
"Another case is if we have a list of numbers, and we we want to sort according to a custom rule.\n",
"\n",
"The built-in sort functions do not care about the details of our data. All they rely on\n",
"are *comparisons*, e.g. the `<`, `>`, and `==` operators. If we equip our class with comparison operators,\n",
Expand Down Expand Up @@ -678,7 +678,7 @@
"metadata": {},
"source": [
"We can perform some simple tests on the operators (insert print statements into the methods if you want\n",
"to verify which function is called)"
"to verify which function is called)."
]
},
{
Expand Down