Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solutions for Nonlinear Equations

Similar presentations


Presentation on theme: "Solutions for Nonlinear Equations"— Presentation transcript:

1 Solutions for Nonlinear Equations
Bisection method Newton-Raphson method

2 Motivation A root, r, of function f occurs when f(r) = 0. For example:
f(x) = x2 – 2x – 3 has two roots at r = -1 and r = 3. f(-1) = – 3 = 0 f(3) = 9 – 6 – 3 = 0 We can also look at f in its factored form. f(x) = x2 – 2x – 3 = (x + 1)(x – 3) November 1, 2019

3 Bisection Method Based on the fact that the function will change signs as it passes thru the root. f(a)*f(b) < 0 Once we have a root bracketed, we simply evaluate the mid-point and halve the interval. November 1, 2019

4 Bisection Method c=(a+b)/2 f(a)>0 f(c)>0 f(b)<0 a c b
November 1, 2019

5 Bisection Method Guaranteed to converge to a root if one exists within the bracket. a = c f(a)>0 c b a f(c)<0 f(b)<0 November 1, 2019

6 Bisection method… Check if solution lies between a and b… F(a)*F(b) < 0 ? Try the midpoint m: compute F(m) If |F(m)| < tol select m as your approximate solution Otherwise, if F(m) is of opposite sign to F(a) that is if F(a)*F(m) < 0, then b = m. Else a = m.

7 Bisection method… This method converges to any pre-specified tolerance when a single root exists on a continuous function Example Exercise: write a function that finds the square root of any positive number that does not require programmer to specify estimates

8 Square root program If the input c < 1, the root lies between c and 1. Else, the root lies between 1 and c. The (positive) square root function is continuous and has a single solution. c = x2 Example: F(x) = x2 - 4 F(x) = x2 - c

9 double Sqrt(double c, double tol)
{ double a,b, mid, f; // set initial boundaries of interval if (c < 1) { a = c; b = 1} else { a = 1; b = c} do { mid = ( a + b ) / 2.0; f = mid * mid - c; if ( f < 0 ) a = mid; else b = mid; } while( fabs( f ) > tol ); return mid; }

10

11

12 Newton-Raphson Method – Graphical View

13


Download ppt "Solutions for Nonlinear Equations"

Similar presentations


Ads by Google