Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods,...

45
Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn

Transcript of Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods,...

Page 1: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Today’s class

• Numerical differentiation• Roots of equation• Bracketing methods

Numerical Methods, Lecture 4 1

Prof. Jinbo Bi CSE, UConn

Page 2: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Finite divided difference

• First forward difference

• First backward difference

Numerical Differentiation

Numerical Methods, Lecture 4 2

Prof. Jinbo Bi CSE, UConn

Page 3: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Centered difference approximation

• Subtract the two equations

Numerical Differentiation

Numerical Methods, Lecture 3 3

Prof. Jinbo Bi CSE, UConn

Page 4: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• First forward difference

Numerical Differentiation

Numerical Methods, Lecture 4 4

Prof. Jinbo Bi CSE, UConn

Page 5: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• First backward difference

Numerical Differentiation

Numerical Methods, Lecture 4 5

Prof. Jinbo Bi CSE, UConn

Page 6: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Centered difference

Numerical Differentiation

Numerical Methods, Lecture 4 6

Prof. Jinbo Bi CSE, UConn

Page 7: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• What is the effect of error in one calculation propagating to subsequent calculations?

• Example:• Multiplying sin x with cos x

• Single variable functions

Error Propagation

Numerical Methods, Lecture 4 7

Prof. Jinbo Bi CSE, UConn

Page 8: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Use Taylor series

Error Propagation

Numerical Methods, Lecture 4 8

Prof. Jinbo Bi CSE, UConn

Page 9: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Error Propagation

Numerical Methods, Lecture 4 9

Prof. Jinbo Bi CSE, UConn

Page 10: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Multivariable functions

Error Propagation

Numerical Methods, Lecture 4 10

Prof. Jinbo Bi CSE, UConn

Page 11: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Condition of a problem is a measure of its sensitivity to changes in input values

• The condition number is defined as the ratio of the relative function error to the relative value error

Numerical stability

Numerical Methods, Lecture 4 11

Prof. Jinbo Bi CSE, UConn

Page 12: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Condition number < 1 indicates a well-conditioned function – i.e. changes in the input are attenuated

• Condition number > 1 indicates a ill-conditioned function – i.e. changes in the input are amplified

Numerical stability

Numerical Methods, Lecture 4 12

Prof. Jinbo Bi CSE, UConn

Page 13: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Roots of equation• Given a function f(x), the roots are those

values of x that satisfy the relation f(x) = 0• Example

• From the quadratic formula, the roots are:

Numerical Methods, Lecture 4 13

Prof. Jinbo Bi CSE, UConn

Page 14: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Roots of Equations• The need to solve for roots show up in

many engineering problems• Also, can be used to find solutions to

implicit variables

Numerical Methods, Lecture 4 14

Prof. Jinbo Bi CSE, UConn

Page 15: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Find a value of R such that current is 5A at t = 1s

Example

Numerical Methods, Lecture 4 15

Prof. Jinbo Bi CSE, UConn

Page 16: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Example

• It is not possible to isolate R to the left side and thus solve for R

• R is know as an implicit variable• Rewrite the function as a function of R

set to 0

Numerical Methods, Lecture 4 16

Prof. Jinbo Bi CSE, UConn

Page 17: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Still need a method to solve for this root• Other examples of difficult to solve roots

Roots of equations

Numerical Methods, Lecture 4 17

Prof. Jinbo Bi CSE, UConn

Page 18: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Non-computer methods• Graphical methods

Roots of equations

Numerical Methods, Lecture 4 18

Prof. Jinbo Bi CSE, UConn

Page 19: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Not exact• Can give you a rough estimate of the root, • Can give you insights on the number of roots

and shape of the curve• Can use the rough estimate in more precise

numerical methods

Graphical methods

Numerical Methods, Lecture 4 19

Prof. Jinbo Bi CSE, UConn

Page 20: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Use to get an initial estimate of the root and also to find out how many roots there are

Graphical methods

Numerical Methods, Lecture 4 20

Prof. Jinbo Bi CSE, UConn

Page 21: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Graphical methods

Numerical Methods, Lecture 4 21

Prof. Jinbo Bi CSE, UConn

Page 22: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Graphical methods

Numerical Methods, Lecture 4 22

Prof. Jinbo Bi CSE, UConn

Page 23: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Graphical methods

Numerical Methods, Lecture 4 23

Prof. Jinbo Bi CSE, UConn

Page 24: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Non-computer/numerical method• Exhaustive search method

• To find the root in the interval [a,b], start at x=a and check if f(a) = 0, then try f(a+Δ), f(a+2Δ), and so on, until we get f(x) sufficiently close to 0

• If the step value Δ is sufficiently small we can obtain an accurate result but this could take an extremely long time. For example, if the interval is [0,10] and the step size is Δ = 0.001, it will take on average 10,000 guesses

• In addition to the inefficiency of this approach, if f(x) is a steep function, this approach may not produce an accurate results

Roots of equation

Numerical Methods, Lecture 4 24

Prof. Jinbo Bi CSE, UConn

Page 25: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Example• Find the root of the function • Actual root is at x=1.0001• With an interval of [0.9, 1.1] and a step size of

Δ = 0.001. The exhaustive search method will test f(1.000) = -0.01 and f(1.001) = 0.086, neither of which are that close to f(x) = 0

Exhaustive search

Numerical Methods, Lecture 4 25

Prof. Jinbo Bi CSE, UConn

Page 26: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• More systematic methods are required• Bracketing methods

• Open methods

Roots of equations

Numerical Methods, Lecture 4 26

Prof. Jinbo Bi CSE, UConn

Page 27: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Locate an interval where sign changes• Divide interval into smaller subintervals

which are then searched for sign changes• Keep repeating until root is found with

sufficient confidence

Incremental search methods

Numerical Methods, Lecture 4 27

Prof. Jinbo Bi CSE, UConn

Page 28: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Also called:• Binary chopping

• Interval halving

• An incremental search method where the interval is cut in half

Bisection method

Numerical Methods, Lecture 4 28

Prof. Jinbo Bi CSE, UConn

Page 29: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Step 1:• Choose lower xl and upper xu such that the

function changes sign over that range – i.e. f(x l) and f(xu) are different signs – or f(xl) f(xu) < 0

• Step 2:• Estimate root to be xr=(xl+xu)/2

Bisection method

Numerical Methods, Lecture 4 29

Prof. Jinbo Bi CSE, UConn

Page 30: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Step 3:• Determine in which subinterval the root lies

• If f(xr)0 is within acceptable tolerance, stop and root equals xr

• If f(xl) f(xr) < 0, then root is in lower subinterval. Set xu = xr, and return to step 2

• If f(xl) f(xr) > 0, then root is in upper subinterval. Set xl = xr, and return to step 2

Bisection method

Numerical Methods, Lecture 4 30

Prof. Jinbo Bi CSE, UConn

Page 31: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Termination criteria• Use approximate relative error calculation to

determine when to stop

• In general, a is larger than t

Bisection method

Numerical Methods, Lecture 4 31

Prof. Jinbo Bi CSE, UConn

Page 32: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Example:

• Use range of [202:204]

• Root is in upper subinterval

Bisection method

Numerical Methods, Lecture 4 32

Prof. Jinbo Bi CSE, UConn

Page 33: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Bisection method

• Use range of [203:204]

• Root is in lower subinterval

–0.0034

Numerical Methods, Lecture 4 33

Prof. Jinbo Bi CSE, UConn

Page 34: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Use range of [203:203.5]

• Root is in upper subinterval

Bisection method

Numerical Methods, Lecture 4 34

Prof. Jinbo Bi CSE, UConn

Page 35: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• The approximate error is upper bound estimate of the true error

• When the root is near one of the ends of the interval, the approximate error is fairly close to the actual true error

• Error is fairly well-contained

Error estimates

Numerical Methods, Lecture 4 35

Prof. Jinbo Bi CSE, UConn

Page 36: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• You always know that the true root is within Δx/2 of your estimate

Error estimates

Numerical Methods, Lecture 4 36

Prof. Jinbo Bi CSE, UConn

Page 37: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

Bisection method

Numerical Methods, Lecture 4 37

Prof. Jinbo Bi CSE, UConn

Page 38: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• You can calculate an error estimate based just on the initial guesses

• You can also make estimates on the error on future iterations

• Superscripts indicates the iteration number

Bisection method

Numerical Methods, Lecture 4 38

Prof. Jinbo Bi CSE, UConn

Page 39: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Each subsequent iteration cuts the approximate error in half

• This, allows to determine a priori exactly how many iterations are needed to arrive at the desired error

Bisection method

Numerical Methods, Lecture 4 39

Prof. Jinbo Bi CSE, UConn

Page 40: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• The false position method works in a similar fashion to the bisection method

• Start with an initial interval [a,b] where f(a) and f(b) have opposite signs, which is the same as the bisection

• Instead of choosing the initial guess xr as the midpoint of the interval, we join the point {a,f(a)} and {b,f(b)} with a straight line and choose xr as the point where that straight line crosses the x-axis.

False Position Method

Numerical Methods, Lecture 4 40

Prof. Jinbo Bi CSE, UConn

Page 41: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

False Position MethodCopyright © The McGraw-Hil l Companies, Inc. Permission required for reproduction or d isplay.Fig 5.12

Numerical Methods, Lecture 4 41

Prof. Jinbo Bi CSE, UConn

Page 42: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Algorithm is the same as bisection method with the same three steps

False Position Method

Numerical Methods, Lecture 4 42

Prof. Jinbo Bi CSE, UConn

Page 43: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Step 1:• Choose lower xl and upper xu such that the

function changes sign over that range - i.e. f(xl) and f(xu) are different signs - or f(xl) f(xu) < 0

• Step 2:• Estimate new root to be

False Position Method

Numerical Methods, Lecture 4 43

Prof. Jinbo Bi CSE, UConn

Page 44: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Step 3:• Determine in which subinterval the root lies

• If f(xr) 0 is within acceptable tolerance, stop and root equals xr

• If f(xl) f(xr) < 0, then root is in lower subinterval. Set xu = xr, and return to step 2

• If f(xl) f(xr) > 0, then root is in upper subinterval. Set xl = xr, and return to step 2

False Position Method

Numerical Methods, Lecture 4 44

Prof. Jinbo Bi CSE, UConn

Page 45: Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.

• Roots of equations• Open methods• Read chapters 5 and 6• HW2, due 9/17

• Chapra & Canale• 6th edition 3.5, 3.7, 3.13, 4.5, 4.6, 4.12 (b) and (d),

and 4.16

Next class

Numerical Methods, Lecture 4 45

Prof. Jinbo Bi CSE, UConn