Presentation is loading. Please wait.

Presentation is loading. Please wait.

MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 31.

Similar presentations


Presentation on theme: "MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 31."— Presentation transcript:

1 MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 31

2 MA/CS 375 Fall 20022 Root Finding Given a real valued function f of one variable (say x), the idea is to find an x such that: f(x) = 0

3 MA/CS 375 Fall 20023 Newton’s Method cont. Repeat the formula to create an algorithm: If at each step the linear model is a good approximation to f then x n should get closer to a root of f as n increases.

4 MA/CS 375 Fall 20024 Newton in Matlab

5 MA/CS 375 Fall 20025 Newton’s Method Without Knowing the Derivative Recall: we can approximate the derivative to a function with:

6 MA/CS 375 Fall 20026 Modification

7 MA/CS 375 Fall 20027 Team Exercise 10 minutes Modify your script to use the approximate derivative (note you will require an extra parameter delta) Test it with some function you do not know the derivative of.

8 MA/CS 375 Fall 20028 Convergence Rate For Newton’s Method Theorem 8 (van Loan p 285) –Suppose f(x) and f’(x) are defined on an interval where and positive constants rho and delta exist such that –If xc is in I, then is in I and –That is x+ is at least half the distance to x* that xc was. Also, the rate of convergence is quadratic.

9 MA/CS 375 Fall 20029 Convergence Rate of Newton’s Method cont The proof of this theorem works by using the fundamental theorem of calculus. All of the restrictions are important – and can be fairly easily broken by a general function The restrictions amount to: 1)f’ does not change sign in a neighbourhood of the root x* 2)f is not too non-linear (Lipschitz condition) 3)the Newton’s iteration starts close enough to the root x* then convergence is guaranteed and the convergence rate is quadratic.

10 MA/CS 375 Fall 200210 Finding A Root Of A Two-dimensional Function of Two Variables Suppose: Specifically:

11 MA/CS 375 Fall 200211 Finding A Root Of A Two-dimensional Function of Two Variables Suppose: Specifically: We can construct a Taylor series:

12 MA/CS 375 Fall 200212 Constructing A Newton Scheme Create a sequence by using this linear approximation to update from (x n,y n ) to (x n+1,y n+1 )

13 MA/CS 375 Fall 200213 Constructing A Newton Scheme We figure that if the linear approximation is good then the f(x n+1,y n+1 ) and g(x n+1,y n+1 ) should be small

14 MA/CS 375 Fall 200214 Two-dimensional Newton Method

15 MA/CS 375 Fall 200215 Jacobian Matrix

16 MA/CS 375 Fall 200216 Jacobian Matrix

17 MA/CS 375 Fall 200217 Team Exercise (Part 1) Code up the two-dimensional Newton solver. Use the approximation for small delta: Use it to find x,y such that:

18 MA/CS 375 Fall 200218 Team Exercise (Part 2) Generalize your Newton Solver to solve: Construct a 3-vector function and find its roots. Plot the position of (xn,yn,zn) using sphere

19 MA/CS 375 Fall 200219 Problems with Multi-D Newton The method relies on inverting the Jacobian matrix. Recall that matrix inversion is strongly dependent on the condition number of the matrix. Clearly, if the root is near a region where the gradient is small then we will run into slow convergence when the search nears the root.

20 MA/CS 375 Fall 200220 Team Exercise: Dodgy Convergence Try to find the (0,0) root of Compare the rate of convergence for the (0,0) root of: For each iteration plot the condition number of the Jacobian matrix. Try several different starting positions.

21 MA/CS 375 Fall 200221 Roots of a Polynomial Suppose we wish to find all the roots of a polynomial of order P Then there are going to be at most P roots!. We can use a variant of Newton’s method.

22 MA/CS 375 Fall 200222 Roots of a Polynomial cont. Suppose we have an initial guess for one of the roots of the polynomial function f Then we can use Newton’s method, starting at this guess to solve for f(x)=0 Once we have found the first root x 1 we apply polynomial deflation to remove this root and then repeat the process to find the next root.

23 MA/CS 375 Fall 200223 Algorithm 1) We are seeking the roots x 1,x 2,..x P of a polynomial f 2) We find x 1 using Newton’s method. 3) We then use Newton’s method to find the next root of f(x)/(x-x 1 ) 4) Then we find x 3 as a root of f(x)/((x-x 1 )(x-x 2 )) 5) Repeat until all roots found

24 MA/CS 375 Fall 200224 Details of Newton’s Algorithm At the k’th step, we need to find a root of For Newton’s we need:

25 MA/CS 375 Fall 200225 Product rule for differentiation

26 MA/CS 375 Fall 200226

27 MA/CS 375 Fall 200227 Newton Scheme For Multiple Root Finding

28 MA/CS 375 Fall 200228 Multiple Root Finder (applied to find roots of Legendre polynomials)

29 MA/CS 375 Fall 200229 Recall: recurrence relation of Legendre polynomials

30 MA/CS 375 Fall 200230 Recall: Recurrence Relation for Gradient of Legendre Polynomials

31 MA/CS 375 Fall 200231 Roots of the 10 th Order Legendre Polynomial Notice how they cluster at the end points

32 MA/CS 375 Fall 200232 Numerical Quadrature A numerical quadrature is a set of two vectors. The first vector is a list of x-coordinates for nodes where a function is to be evaluated. The second vector is a set of integration weights, used to calculate the integral of a function which is given at the nodes

33 MA/CS 375 Fall 200233 Example of Quadrature Say we wish to calculate an approximation to the integral of f over [-1,1] : Suppose we know the value of f at a set of N points then we would like to find a set of weights w 1,w 2,..,w N so that:

34 MA/CS 375 Fall 200234 Newton-Cotes Formula The first approach we are going to use is the well known Newton-Cotes quadrature. Suppose we are given a set of points x 1,x 2,..,x N. Then we require that the constant is exactly integrated:

35 MA/CS 375 Fall 200235 Now we require that 1,x,x 2,..,x N-1 are integrated exactly

36 MA/CS 375 Fall 200236 In Matrix Notation: Notice anything familiar?

37 MA/CS 375 Fall 200237 It’s the transpose of the Vandermonde matrix

38 MA/CS 375 Fall 200238 Integration by Interpolation In essence this approach uses the unique (N-1)’th order interpolating polynomial If and integrates the area under the If instead of the area under f Clearly, we can estimate the approximation error using the estimates for the error in the interpolation we used before.

39 MA/CS 375 Fall 200239 Newton-Cotes Weights

40 MA/CS 375 Fall 200240 Using Newton-Cotes Weights

41 MA/CS 375 Fall 200241 Using Newton-Cotes Weights (Interpretation) i.e. we calculate the coefficients of the interpolating polynomial expansion using the Vandermonde, then since we know the integral of each term we can sum up the integral of each term to get the total.

42 MA/CS 375 Fall 200242 Matlab Function for Calculating Newton-Cotes Weights

43 MA/CS 375 Fall 200243 Demo: Matlab Function for Calculating Newton-Cotes Weights 1)set N=5 points 2)build equispaced nodes 3)calculate NC weights 4)evaluate F=X^3 at nodes 5)evaluate integral 6)F is anti-symmetric on [-1,1] so its integral is 0 7)Answer correct

44 MA/CS 375 Fall 200244 Team Exercise Get the directory Lecture19m from the cd-rom make sure your matlab path points to the copy of this directory using a script figure out what order polynomial the weights can exactly integrate for a given set of N points (say N=6).

45 MA/CS 375 Fall 200245 Gauss Quadrature The construction of the Newton-Cotes weights does not utilize the ability to choose the distribution of nodes for greater accuracy. We can in fact choose the set of nodes to increase the order of polynomial that can be integrated exactly using just N points.

46 MA/CS 375 Fall 200246 Suppose:

47 MA/CS 375 Fall 200247 Suppose: Remainder term, which must have p roots located at the interpolating nodes

48 MA/CS 375 Fall 200248 At this point we can choose the nodes {x i }. If we choose them so that they are the p+1 roots of the (p+1)’th order Legendre function then s(x) is in fact the N=(p+1)’th order Legendre function itself!.

49 MA/CS 375 Fall 200249 But we also know that if r is a lower order polynomial than (p+1)’th order, it can be expressed as a linear combination of Legendre polynomials and is in fact orthogonal to L p+1

50 MA/CS 375 Fall 200250 i.e. the quadrature is exact for all polynomials of order up to p=(2N-1) Hence:

51 MA/CS 375 Fall 200251 Summary of Gauss Quadrature We can use the multiple root finder to locate the roots of the N’th order Legendre polynomial. We can then use the Newton-Cotes formula with the roots of the N’th order Legendre polynomial to calculate a set of N weights. We now have a quadrature !!! which will integrate polynomials of order 2N-1 with N points

52 MA/CS 375 Fall 200252 Team Exercise Use the root finder and Newton-Cotes routines to build a quadrature for N points (N arbitrary). Test it on some functions you know the integral of (sin(x) or tan(x) or exp(x) or …) over the interval [-1,1]

53 MA/CS 375 Fall 200253 Summary We have looked at two ways to find the root of a single valued, single parameter function We considered a robust, but “slow” bisection method and then a “faster” but less robust Newton’s method which we generalized to vector functions of multiple arguments We discussed the theory of convergence for Newton’s method.


Download ppt "MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 31."

Similar presentations


Ads by Google