530 likes | 582 Views
Learn Newton's Method, convergence rates, and constructing a Newton scheme in MATLAB for finding roots of functions. Understand the theory behind Newton's algorithm with practical exercises.
E N D
MA/CS 375 Fall 2002 Lecture 31 MA/CS 375 Fall 2002
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 MA/CS 375 Fall 2002
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 xn should get closer to a root of f as n increases. MA/CS 375 Fall 2002
Newton in Matlab MA/CS 375 Fall 2002
Newton’s Method Without Knowing the Derivative • Recall: we can approximate the derivative to a function with: MA/CS 375 Fall 2002
Modification MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
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: • f’ does not change sign in a neighbourhood of the root x* • f is not too non-linear (Lipschitz condition) • the Newton’s iteration starts close enough to the root x* then convergence is guaranteed and the convergence rate is quadratic. MA/CS 375 Fall 2002
Finding A Root Of A Two-dimensional Function of Two Variables • Suppose: • Specifically: MA/CS 375 Fall 2002
Finding A Root Of A Two-dimensional Function of Two Variables • Suppose: • Specifically: • We can construct a Taylor series: MA/CS 375 Fall 2002
Constructing A Newton Scheme Create a sequence by using this linear approximation to update from (xn,yn) to (xn+1,yn+1) MA/CS 375 Fall 2002
Constructing A Newton Scheme We figure that if the linear approximationis good then the f(xn+1,yn+1) and g(xn+1,yn+1)should be small MA/CS 375 Fall 2002
Two-dimensional Newton Method MA/CS 375 Fall 2002
Jacobian Matrix MA/CS 375 Fall 2002
Jacobian Matrix MA/CS 375 Fall 2002
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: MA/CS 375 Fall 2002
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 MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
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 x1 we apply polynomial deflation to remove this root and then repeat the process to find the next root. MA/CS 375 Fall 2002
Algorithm 1) We are seeking the roots x1,x2,..xP of a polynomial f 2) We find x1 using Newton’s method. 3) We then use Newton’s method to find the next root of f(x)/(x-x1) 4) Then we find x3 as a root of f(x)/((x-x1)(x-x2)) 5) Repeat until all roots found MA/CS 375 Fall 2002
Details of Newton’s Algorithm • At the k’th step, we need to find a root of For Newton’s we need: MA/CS 375 Fall 2002
Product rule for differentiation MA/CS 375 Fall 2002
Newton Scheme For Multiple Root Finding MA/CS 375 Fall 2002
Multiple Root Finder(applied to find roots of Legendre polynomials) MA/CS 375 Fall 2002
Recall: recurrence relation of Legendre polynomials MA/CS 375 Fall 2002
Recall: Recurrence Relation for Gradient of Legendre Polynomials MA/CS 375 Fall 2002
Roots of the 10th Order Legendre Polynomial Notice how they cluster at the end points MA/CS 375 Fall 2002
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 MA/CS 375 Fall 2002
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 w1,w2,..,wN so that: MA/CS 375 Fall 2002
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 x1,x2,..,xN. Then we require that the constant is exactly integrated: MA/CS 375 Fall 2002
Now we require that 1,x,x2,..,xN-1are integrated exactly MA/CS 375 Fall 2002
In Matrix Notation: Notice anything familiar? MA/CS 375 Fall 2002
It’s the transpose of the Vandermonde matrix MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
Newton-Cotes Weights MA/CS 375 Fall 2002
Using Newton-Cotes Weights MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
Matlab Function for Calculating Newton-Cotes Weights MA/CS 375 Fall 2002
Demo: Matlab Function for Calculating Newton-Cotes Weights • set N=5 points • build equispaced nodes • calculate NC weights • evaluate F=X^3 at nodes • evaluate integral • F is anti-symmetric on [-1,1] so its integral is 0 • Answer correct MA/CS 375 Fall 2002
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). MA/CS 375 Fall 2002
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. MA/CS 375 Fall 2002
Suppose: MA/CS 375 Fall 2002
Remainder term, whichmust have p roots locatedat the interpolating nodes Suppose: MA/CS 375 Fall 2002
At this point we can choose the nodes {xi}. 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!. MA/CS 375 Fall 2002
But we also know that if r is a lower order polynomial than (p+1)’th order, it can be expressedas a linear combination of Legendre polynomialsand is in fact orthogonal to Lp+1 MA/CS 375 Fall 2002
Hence: i.e. the quadrature is exact for all polynomials of order up to p=(2N-1) MA/CS 375 Fall 2002