NUMERICAL ANALYSIS WEEKLY OVERVIEW M. AUTH 1. Monday 28 August Students are encouraged to download Anaconda Python. Anaconda is a version of Python that comes with some numerical packages (numpy and matplotlib) as well as an IDE (Spyder) that we will use in this course. I ve added a link to our website with instructions for you to download Anaconda. Please download version Python 3.6, since this is the version of Python used in our book. In class we started to do some Python programming from Chapter 2. We covered Example 2.2, Exercise 2.6, and the if statement in Section 2.3.1. 2. Wednesday 6 September We worked through some examples and exercises in the second Chapter of Newman s book. Please work through this Chapter on your own and with groups of students. It is important to become comfortable with these basic programming idioms. One good way to become more comfortable with the code in Chapter 2 is to experiment by changing indentation or introducing a print statement in order to track a variable. It is particularly important that you understand lists, arrays, and for loops. We will be using them over and over during the semester. 3. Monday 11 September We finished chapter 2 by spending some time working through the multiple loops required to approximate the Madelung constant in Exercise 2.9. We also talked about user defined functions as being a way to hide detail in our code. It is a good idea to review the good style recommendations in chapter 2 as you progress through the course. We also covered chapters 3 and 4. Neither chapter is a focus of our course but it is helpful to become comfortable with both. When faced with a difficult computation it is often helpful to view some of the output (approximations) geometrically. Chapter 3 explains how to view graphs in python and how to include others data files in your code. Chapter 4 discusses computer rounding error. 4. Monday 18 September We started to work through Peter Olver s Lecture Notes on Numerical Analysis. Please read the first two lectures. We covered the first lecture and then made about half-way through the second in class on Monday. We proved our first theorem of the course, proposition 2.2. Please read the lecture notes 1 and 2, and then attempt to do the supplementary homework problems on our webpage. We will finish lecture 2 next week. 1
2 M. AUTH Here is the code we used in class to generate solutions (sequences) to discrete dynamical systems u (k+1) = g(u (k) ). # Discrete Dynamical System Algorithm def g(u): """Discrete Dynamical System u=g(u)=0.5*u""" return 0.5*u u = 7.83 # u_0 = seed for k in range(25): print(k,u) # prints the first 25 elements of sequence u = g(u) 5. Monday 25 September We talked about how some fixed points are stable and others are unstable. It is a waste of time to try to approximate an unstable fixed point using a discrete dynamical system. We found two ways to identify the stability of a fixed point: 1. Draw a stair diagram 2. Use the following theorem from Olver s notes Theorem 5.1. (Theorem 2.6 in Olver s Notes) Let g(u) be continuously differentiable. Suppose that u = g(u ) is a fixed point. If g (u ) < 1, then u is an asymptotically stable fixed point. On the other hand if g (u ) > 1, then u is an unstable fixed point, the only iterates which converge to it are those that land exactly on it. Proof. ANALYSIS IN MATH 328 USES INEQUALITIES e (k) = u (k) u Mean Value Theorem: e (k+1) = g (v)e (k) If g (v) σ < 1 for all v close to u then e (k) σ e (k 1) σ 2 e (k 2)... σ k e (0) if the u (0) is close to u. hence lim k e (k) = lim k u (k) u = 0. 6. Monday 2 October We defined periodic orbits and quadratic convergence. A period k orbit of a discrete dynamical system is a solution that satisfies u (n+k) = u (n) for all n. Theorem 6.1. (THEOREM 2.10 Olver s Notes) Suppose that g C 2, and u = g(u ) and g (u ) = 0. Then for all iterates u (k) sufficiently close to u, the errors e (k) = u (k) u satisfy the quadratic convergence estimate: e (k+1) τ e (k) 2 for some constant τ > 0. In conclusion quadratic convergence is preferable. Start with u (0) having one decimal place accuracy. Linear Convergence (and σ =.1) : It requires 49 iterations to obtain 50 decimal place accuracy. Quadratic Convergence (and τ = 1) : It requires 6 iterations to obtain 64 decimal place accuracy.
NUMERICAL ANALYSIS WEEKLY OVERVIEW 3 Theorem 6.2. (Theorem 2.17 NEWTON S METHOD in Olver s Notes) f C 2, f(u ) = 0, f (u ) 0 then Newton s iteration converges at quadratic rate if seed is sufficiently close. Example 6.3. Approximate a root of 0 = f(x) = cos x x using (1) Any fixed point method from math import cos def g(u): return cos(u) u = 1 print(0,u) for k in range(1,27): u = g(u) print(k,u) (2) Newton s method (a better fixed point method) from math import cos, sin def f(x): return cos(x) - x def f_prime(x): return -sin(x) - 1 u = 1 print(0,u) for k in range(1,7): u = u - f(u)/f_prime(u) print(k,u) (3) Bisection method. from math import cos def f(x): return cos(x) - x a,b = 0,5 # we know f(a)>0 and f(b)<0 and f is continuous for k in range(25): mid = (a+b)/2 print(k,mid) if f(mid) > 0: a,b = mid,b else: a,b = a,mid
4 M. AUTH 7. Wednesday 11 October Covered algorithms and code for left Riemann sums, trapezoid method, and Simpson s method. We did not cover the error formulas and they will not be on Exam 1. Make sure you understand how the algorithms work. from math import sin def f(x): return sin(x) def left_endpoint(f,a,b,n): """Computes left endpoint Riemann sum approx of integral of f from a to b using n equally spaced intervals.""" S = 0 deltax = (b-a)/n for k in range(n): S += f(a + k*deltax)*deltax return S #for i in range(1,20): # print(i,left_endpoint(f,0,2,i)) 8. Monday 16 October We covered the first two sections of Olver s notes 4. Gaussian Elimination. We worked through many examples of how the Gaussian Elimination algorithm works. We did not implement Gaussian Elimination in Python so the code for Gaussian Elimination will not be part of exam 1. We only implemented code to multiply matrices A and B: from numpy import array, zeros A = array([[1,2,3], [0,9,-1], [6,-2,0]], float) B = array([[7,0], [-2,-1], [1,0]], float) n,m = len(a),len(b[0]) p = len(b) C = zeros((n,m)) for i in range(n): for j in range(m): for k in range(p): C[i][j] += A[i][k] * B[k][j] print(c) You should know how this code works (triple loops) but you should never use it in practice. Instead use numpy s dot function. Here is how you would do the same as above using dot: from numpy import array, dot
NUMERICAL ANALYSIS WEEKLY OVERVIEW 5 A = array([[1,2,3], [0,9,-1], [6,-2,0]], float) B = array([[7,0], [-2,-1], [1,0]], float) C = dot(a,b) print(c) 9. Monday 23 October Finish Olver s notes 4. Gaussian Elimination and start 5. Inner Products and Norms. Short review for exam 1. Exam 1 on Wednesday. Focus on the supplemental hw problems. Reread notes and make sure you understand the programming concepts introduced in Newman Chapters 1 3. 10. Monday 30 October We discussed Olver s notes 5. Inner Products and Norms and 7. Iterative Methods for Linear Systems (only first three pages, through p. 105). We also spent a full day reviewing linear algebra. In particular we discussed independence, spanning, and basis. If you feel as if you need more review of linear algebra, you can watch Gilbert Strang s video lectures 2-5, 6(only first 30 minutes), 9(only first 38 minutes). There is a link to these videos on our webpage. 11. Monday 6 November Read sections 6.1 6.3 in Olver s notes. Watch Strang s video Lecture 22 Diagonalization and Powers of A from 26:30 end. Read sections 7.1, 7.2, and 8.1. 12. Monday 13 November Read sections 7.3 and 7.4 in Olver s notes (in section 7.4 only read through end of p. 122 you will not be tested on the Gauss-Seidel or SOR methods). Read Olver s notes 9. Numerical Solutions of Algebraic Systems. Read Newman s section 6.2 Eigenvalues and Eigenvectors as well as section 6.3.7 Newton s Method For Two Or More Variables. If you prefer to learn by watching videos, watch Strang s video lecture 17 Orthogonal Matrices and Gram-Schmidt (we will cover projections after Thanksgiving break.) 13. Monday 20 November Read Olver s notes 10 (up to and including EXAMPLE 10.19) Numerical Solutions of Ordinary Differential Equations. Skim Newman s Chapter 8 Ordinary Differential Equations (ONLY p. 327 335) looking for Python code. If you prefer to learn via videos, there is a lot of good information in Arthur Mattuck s first two lecture videos: Lecture 1. The geometry of y = f(x, y) and Lecture 2. Euler s Numerical Method for y = f(x, y). There is a link to these videos on our webpage.
6 M. AUTH 14. Monday 27 November Finish Olver s Notes 10 and Newman 8.1 8.4. WEDESDAY EXAM will cover material we covered from Monday 16 October up to and including the material Monday 20 November on Differential equations. You should understand Theorem 4.3, Theorem 4.7, Proposition 6.9, Theorem 6.14, Theorem 6.17, Theorem 7.2, Theorem 7.11, Corollary 7.19, Theorem 7.26, Theorem 9.2, Theorem 9.3, and Theorem 10.8 from Olver s notes. You need not know how to rigorously prove each of these theorems but you should know each of their hypotheses and conclusions. Most importantly you should know how they are used. 15. Monday 4 December Read Olver s notes 13. Approximation and Interpolation. Skip sections Approximation and Interpolation by General Functions and Weighted Least Squares, i.e. you need not read pages 231 234. References