Download presentation
Presentation is loading. Please wait.
Published byJohnathan Shields Modified over 8 years ago
1
Root Finding UC Berkeley Fall 2004, E77 http://jagger.me.berkeley.edu/~pack/e77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. http://jagger.me.berkeley.edu/~pack/e77http://creativecommons.org/licenses/by-sa/2.0/
2
Solving Algebraic Equations From linearity, it is easy to solve the equation or even the system of equations But what about an equation like
3
Solving Algebraic Equations In general, given a continuous function f, how do you find the (any, all) solutions to Graph of f(x) versus x x f(x) “ roots ” of f
4
Iterative Methods Iterative methods start with a “guess”, labeled x 0 and through “easy” calculations, generate a sequence x 1, x 2, x 3, … Goal is that sequence satisfies and convergence to a limit, x* x* is a solution
5
Rate of Convergence Suppose {x n } is a sequence, converging to a limit x*. Let e n denote the difference x*-x n If there is a constant C, and positive exponent such that for large n then the sequence {x n } converges with order to x*. –“linear” convergence is =1 The sequence 3, 2.5, 2.25, 2.125, 2.0625, … converges linearly to 2 (here C = ½) The sequence 3, 2.1, 2.01, 2.001, 2.0001,… converges linearly to 2 (here C=0.1) –“quadratic” convergence is =2 The sequence converges quadratically to 2 (here C=1)
6
Stopping Criteria Suppose {x n } is a sequence, converging to a limit x*. The limit x* has the property f(x*)=0. Let tol be a positive number Absolute (in x) |x n – x*| < tol Relative (in x) |x n – x*| < tol × |x*| Absolute in f |f(x n )| < tol But we don ’ t know x* “ Absolute ” |x n – x n-1 | < tol “ Relative ” |x n – x n-1 | < tol × |x n | Sometimes (in bisection, for example) we can bound this, even without knowing x*.
7
Bisection Method, basic idea Suppose f is continuous, There must be a root x* between x L and x R. Let x M be the midpoint. |x M -x*|≤0.5|x R -x L | Based on sign of replace either x L or x R with x M, and repeat. Intermediate value theorem
8
Simple pseudo-code: Bisection % Start with xL, xR, fL = f(xL); fR = f(xR); while StoppingCriteriaNotMet xM = 0.5*(xL+xR); yM = f(xM); if fL*fM<0 % replace R with M xR = xM; else xL = xM; end
9
Examples: Bisection
10
Newton’s Method: motivation graph of f(x) Graph of h(x), the straight-line approximation to f at x 0 functions are equal at x 0 slope of h (everywhere) equals the slope of f at x 0 graph of h is straight line
11
Newton’s Method: motivation graph of f(x) Graph of h(x), the straight-line approximation to f at x 0 Approximation to f, near x 0 Approximate solving f(x)=0 by solving (easier) h(x)=0
12
Newton’s Method: iteration graph of f(x) Graph of h(x), the straight-line approximation to f at x 0 Algorithm: Repeat, using x* app as the “ initial ” point. General form of the iteration
13
Newton’s Method: iteration General form of the iteration Facts about Newton ’ s method to solve f(x) = 0 At each step, need to evaluate the function and its derivative at a single point Not guaranteed to converge. It might “ cycle ”, and it might diverge. If it does converge, the convergence is quadratic. More complicated than bisection, can work better. Generalizes to N equations in N unknowns
14
Function handles and feval Several Matlab functions solve your problem by repeatedly calling functions that you supply –finding zeros of a function ( fzero ) –Integrating a function ( trapz, quad ) –Integrating a differential equation ( ode45 ) –minimizing a function ( fminbnd, fminsearch ) For example, in calling fzero, you must pass a reference- to-the-function (called a function handle) that you want fzero to find the zeros of. Use the @ operator to get the reference. >> shan = @sin; >> class(shan) >> feval(shan,linspace(0,pi,5)) New data type: add to list with double, cell, char, struct. Any function (built-in, mfile, etc)
15
Function handles and feval General syntax for feval is [out1,out2,…] = feval(FuncH,arg1,arg2,…) Output argument list function handle Input argument list
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.