ChEn263 — 2020 Winter Course Notes
Numerical Computing
Lectures 1-3: Foundations of Numerical Computing
- Lecture 1 - Numerical Computing (Notes).
There are the course notes for the first lecture, introducing the concepts of analytical and numerical solutions.
This lecture also discusses different classes of mathematical problems e.g. linear/nonlinear systems, coupled/uncoupled systems, algebraic/differential systems.
- Example - Numerical Solution. Example of a numerical solution to a nonlinear algebraic equation.
- Example - Numerical Solution. Example of a numerical solution to a nonlinear algebraic equation.
- Lecture 2 - Intro to Excel and Python (Notes).
This lecture is an introduction to a spreadsheet program (Excel) and a structured programming language (Python).
This lecture also discusses the idea of a computer and its basic components (input/output, memory, CPU).
- Example - Intro to Excel. This Excel workbook and the video below provide some examples of Excel basics including: navigating excel, copy and paste, cell locking, cell formatting and more.
- Example - Python Hello World, Intro to Python. These two Python files and the video below provide an introduction to a first “hello world” program in Python. The video also provides a brief explanation of how to install the Anaconda distribution (i.e. Spyder) in Microsoft Windows.
- Lecture 3 - Units and Error (Notes).
These are course notes for the Lecture 3, discussing the concept of units, unit conversions, data types (boolean variables, strings, integers, and floating point values). Examples with Excel and Python are given below. There is also a video recording of this lecture with an additional set of notes that go with the video.
- Handout - “Big 13” Units. This is a handout of the most common units that we will use, and it contains the unit conversions that you must memorize for the course.
- Lecture 3 Slides (Rami). These are the lecture notes converted into slides. Thanks Rami!
- Example - Units in Excel, Example - Data Types and Error in Python. These examples cover unit conversions and the use of different data types in Excel and Python. The video below goes through both of these examples in detail.
Lectures 4-5: Structured Programming
- Lecture 4 - Functions (Notes). These are course notes for Lecture 4, covering the concept of functions. Examples are given in Excel and Python below.
- Example - Functions in Excel. This is an example spreadsheet showing the use of functions (i.e. formulas) in Excel.
- Example - Functions in Python. This is an example Python code that shows the use of functions in Python. It includes the use of modules (i.e. math, numpy), how to call a function and how to define a function.
- Lecture 5 - Conditionals (Notes). These notes accompany Lecture 5 on conditional statements including
if
-else
statements, Boolean logic, and comparison operators.- Example - Conditionals in Excel. This is a spreadsheet showing the use of
if
,countif
andsumif
functions.
- Example - Conditionals in Python. This is an example Python code showing the use of
if
-statements,if
-else
statements, andif
-elif
-else
statements. It also shows some examples of Boolean logic and comparison operators.
- Example 2 – Conditionals in Python, Key.
This is another example showing the use of conditional operations in Python. This example is meant for extra practice.
- Example - Conditionals in Excel. This is a spreadsheet showing the use of
Lectures 6-9: Loops, etc.
- Lecture 6 - Loops (Notes). These notes accompany Lecture 6 on loops, including
for
loops andwhile
loops.- Example - Loop-like statements in Excel, Example - Loops in Python. These files contain an example of an Excel workbook with loop-like statements and a Python code showing the use of loops. The video below works through these examples.
- Lecture 7 - Arrays (Notes). This lecture discusses the concepts and uses of arrays, the data type that holds vectors and matrices in Python.
The lecture covers three different types of arrays that occur in Python: lists, tuples, and numpy arrays.
There is a video that I made of the full lecture and a set of notes that go with the video recording.
- Example 1 - Array Basics in Python. This file contains some examples of the basics of using arrays in Python. The video below works through these examples in detail.
- Example 2 - Loops and Array Math in Python. This file contains examples using arrays in Python to do some example math problems including sums, dot products and matrix multiplication. In addition, this video shows how to use loops with arrays. The video below works through these examples.
- Lecture 8 - File I/O and Plotting (Notes).
This lecture discusses fundamental concepts needed for reading and saving data from text files (File I/O).
These notes are relatively short, but there are more extensive examples for this lecture.
The video below is a recording of Lecture 8 covering these notes.
- Lec08-Data_Files.zip. This zipped file contains data needed for the examples below. Unzip/uncompress the file to access the data files.
- Example - File I/O and Plotting in Excel. The file in the link and the video below show how to perform File I/O in Excel and how to make scatter plots.
- Example - File I/O and Plotting in Python.
The file in the link and the video below show how to perform File I/O in Python using
loadtxt
andsavetxt
and how to make scatter plots using thematplotlib.pyplot
module.
- Lecture 9 - Debugging (Notes). This lecture discusses the programming cycle, different types of bugs and some tips for debugging code.
The video below goes through this lecture in detail and then shows how to use the discussed debugging techniques on two examples of buggy code.
- The buggy examples (and the corresponding solutions) that accompany Lecture 9 can be found here: Lec09-Examples.zip.
- These extra lecture notes were produced while making the video. Note that in the last debugging examples (at the end of the video) I forget two things: (1) I omit some parentheses and (2) I forgot to change a power from 1/2 to 2.
Numerical Algebra
Lectures 10-12: Linear Algebra
- Lecture 10 - Review of Matrix Algebra (Notes). These notes review some concepts from linear algebra, including how to convert a linear system to a matrix, index notation and the Gauss Elimination algorithm for solving a matrix.
- Example (from Lecture 7) - Loops and Array Math in Python. This file contains examples using arrays in Python to do some example math problems including sums, dot products and matrix multiplication. The video below works through these examples.
- Lecture 11 - Gauss Elimination (Notes). These notes cover the Gauss Elimination algorithm, its index notation and how to program the algorithm.
- Lecture 12 - Numpy Linear Algebra (Notes). These notes cover array math functions and linear algebra in Python. They also cover the concept of computational cost in terms of memory and CPU time and a brief introduction to asymptotic notation.
Lectures 13-16: Nonlinear Algebra
- Lecture 13 - Fixed Point Methods (Notes). These notes cover iterative “fixed-point” methods to solve a non-linear equation. These methods include Picard’s method and Newton’s method.
- Lecture 14 - NLEs in Scipy (Notes). This lecture covers systems of nonlinear equations and how to solve them in Python.
Examples showing how to solve NLEs in Scipy are given in the python file below.
In addition, a video of the complete lecture is provided with another set of notes corresponding to the video lecture.
- Lecture 15 - Optimization (Notes).
This lecture covers the basics of optimization and how to use optimization methods in Excel and Python.
This includes the use of Excel’s Solver tool and the
scipy.optimize.minimize
function in Python. Examples showing how to use these tools in an Excel file and a python file below. In addition, a video of the complete lecture is provided with another set of notes corresponding to the video lecture. - Lecture 16 - Engineering Problems (Notes). This lecture covers some tips for solving linear and nonlinear engineering problems using Python and Excel.
- Case Study: DNA force extension. Thanks to Dorfman and Dautidis for the example problem!
- Case Study Key. This is the answer key to the previous problem.
Numerical Calculus
Lectures 17-20: Interpolation and Integration
- Lecture 17 - Least Square Fitting (Notes). This lecture covers the concept of using a least squares procedure to fit a function, incluing the idea of minimizing the sum of the squared error, and finding the coefficient of determination (i.e. R-squared).
The video below covers this material as well as examples in Excel and Python.
Extra video notes can be found here. - Lecture 18 - Interpolation (Notes). This lecture covers the concept of interpolation by hand, in Excel and in Python.
I cover linear interpolation and the basic concepts of quadratic and cubic splines.
The video covers examples of linear interpolation in Excel and linear/quadratic/cubic splines in Python.
Extra video notes can be found here.
- Lecture 19 - Newton-Coates Integration (Notes). In this lecture, we cover Newton-Coates integration formulas, and in particular the trapezoidal rule.
We then cover the use of Newton-Coates formulas to do numerical integration (i.e. quadrature) in Excel and Python.
Extra video notes can be found here.
There is an older version of this video from a previous year that can be found here.
- Lecture 20 - Jupyter and Scipy Integrals (Notes - Jupyter Notebook, Notes - pdf).
If you are having a hard time downloading the notebook right-click here and select “Save link as”.
In this lecture, I introduce the Jupyter Notebook and the Sympy module for doing symbolic manipulation in Python.
I also cover how to use the Scipy.Integrate module to do numerical integrals using the Quad and Simps functions.
Lectures 21-23: Initial Value Problems
- Lecture 21 - ODEs and Explicit Euler (Notes).
In this lecture, I introduce differential equations and some notation and concepts related to categorizing differential equations.
I then discuss how to solve a first-order, ODE, IVP using the Explicit Euler method.
Examples in Python and Excel are discussed.
Extra video notes can be found here.
- Lecture 22 - Systems of ODEs (Notes).
In this lecture, I introduce systems of ODEs and talk about how to write them in standard form.
I also discuss how to turn a higher-order ODE (e.g. something 2nd or 3rd order) and turn it into a system of first-order ODEs.
These concepts are discussed in the first video embedded below.
Extra video notes can be found here.
The second video contains examples in Python using the “solve_ivp” function from the “scipy.integrate” module. - Lecture 23 - Integrating Excel and Python (Notes).
In this lecture, I discuss two ways of introducing more programming concepts in Excel.
The first involves directly programming in Visual Basic for Applications (VBA), the scripting language included with Excel.
The second uses the XLWings module to integrate Python with Excel, thus extending Python’s functionality to Excel.
VBA is discussed in the first video and XLWings is discussed in the second.
Extra handouts about the syntax for using both VBA and XLWings are included below as well.
Extra video notes can be found here.