Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some Comments on Root finding

Similar presentations


Presentation on theme: "Some Comments on Root finding"β€” Presentation transcript:

1 Some Comments on Root finding

2 Avoid subtraction of nearly equal numbers
Some Comments on Root finding Consider the following two numbers a= ; b= ; c = a - b ans = Avoid subtraction of nearly equal numbers a=1e-16; b=1; c=-1; a+(b+c) (a+b)+c Associative property π‘Ž+ 𝑏+𝑐 = π‘Ž+𝑏 +𝑐 ans = e-16 why

3 Avoid subtraction of nearly equal numbers
Some Comments on Root finding Avoid subtraction of nearly equal numbers % solve x^2 + b*x + 1 = 0 f x*(a*x+b)+c; xeps = 1e-8; b = (2/xeps) + xeps; a=1; c=1; f a*x^2 + b*x +c x1 = (-b+sqrt(b^2-4*a*c))/(2*a) y1=(-2*c)/(b+sqrt(b^2-4*a*c)) f(x1) f(y1) abs((x1-y1)/y1)*100 Solve: π‘₯ 2 +𝑏 π‘₯+1=0 𝑏=2Γ— 10 8 π‘₯ 1 = βˆ’π‘+ 𝑏 2 βˆ’4π‘Žπ‘ 2π‘Ž rationalizing the numerator x1 = y1 = e-09 ans = 100 π‘₯ 1 = βˆ’2𝑐 𝑏+ 𝑏 2 βˆ’4π‘Žπ‘

4 Avoid subtraction of nearly equal numbers
Some Comments on Root finding Avoid subtraction of nearly equal numbers The Secant Method Algebraically equivalent formula π‘₯ 𝑛+1 = π‘₯ 𝑛 βˆ’ 𝑓( π‘₯ 𝑛 )( π‘₯ 𝑛 βˆ’ π‘₯ π‘›βˆ’1 ) 𝑓 π‘₯ 𝑛 βˆ’π‘“( π‘₯ π‘›βˆ’1 ) π‘₯ 𝑛+1 = π‘₯ π‘›βˆ’1 𝑓 π‘₯ 𝑛 βˆ’ π‘₯ 𝑛 𝑓 π‘₯ π‘›βˆ’1 𝑓 π‘₯ 𝑛 βˆ’π‘“( π‘₯ π‘›βˆ’1 ) in general, this iteration equation is likely to be less accurate than the one given in left box. why Here, we subtract two nearly equal numbers in both numerator and denominator.

5 Formula Error Equation guess
Some Comments on Root finding Formula Error Equation guess x0 suff close to x* Any π‘₯ 𝑛+1 = π‘₯ 𝑛 βˆ’ 𝑓( π‘₯ 𝑛 ) 𝑓′( π‘₯ 𝑛 ) π‘₯ βˆ— βˆ’ π‘₯ 𝑛+1 = 𝑓 2 πœ‰ 2 𝑓 β€² π‘₯ 𝑛 π‘₯ βˆ— βˆ’ π‘₯ 𝑛 2 Newton’s Secant π‘₯ 𝑛+1 = π‘₯ 𝑛 βˆ’ 𝑓( π‘₯ 𝑛 )( π‘₯ 𝑛 βˆ’ π‘₯ π‘›βˆ’1 ) 𝑓 π‘₯ 𝑛 βˆ’π‘“( π‘₯ π‘›βˆ’1 ) π‘₯ 𝑛+1 = π‘Ž 𝑛 + 𝑏 𝑛 2 π‘₯ βˆ— βˆ’ π‘₯ 𝑛 ≀ π‘βˆ’π‘Ž 2 𝑛 Bisection Fixed-point π‘₯ 𝑛+1 =𝑓( π‘₯ 𝑛 ) π‘₯ βˆ— βˆ’ π‘₯ 𝑛 ≀ π‘˜ 𝑛 π‘₯ βˆ— βˆ’ π‘₯ π‘›βˆ’1 𝑔′(π‘₯) β‰€π‘˜ βˆ€π‘₯ False position Secant +test

6 Some Comments on Root finding
Cq1 solution Cq2 solution

7 Apply Newton’s method to find a solution to π‘₯βˆ’6π‘π‘œπ‘ π‘₯=0, π‘₯ 0 =2
Some Comments on Root finding Apply Newton’s method to find a solution to π‘₯βˆ’6π‘π‘œπ‘ π‘₯=0, π‘₯ 0 =2 In the interval [0,πœ‹] that is accurate to within 10 βˆ’3 π‘₯ 𝑛+1 = π‘₯ 𝑛+1 βˆ’ π‘₯βˆ’6π‘π‘œπ‘ π‘₯ 1+6sin⁑(π‘₯) Newton’s method: 𝑛 π‘₯ 𝑛 π‘₯ 𝑛+1 βˆ’ π‘₯ 𝑛 e-01 e-02 e-04 e-09

8 Multiple Root Some Comments on Root finding
π‘₯=1 is a zero of multiplicity 2 of the the function 𝑓 π‘₯ = (π‘₯βˆ’1) 2 (π‘₯βˆ’3) 2 Note that no change of sign close to the root. (bisection ,FP ??) Definition: Theorem p of f (x) = 0 is a zero of multiplicity m of f if for π‘₯=𝑝, we can write 𝑓 π‘₯ = (π‘₯βˆ’π‘) π‘š π‘ž π‘₯ where π‘ž(𝑝)β‰ 0 p is a zero of multiplicity m of f if and only if 𝑓 𝑝 = 𝑓 (1) 𝑝 =β‹―= 𝑓 π‘šβˆ’1 𝑝 =0 and 𝑓 (π‘š) 𝑝 β‰ 0

9 Multiple Root Some Comments on Root finding Example:
Show that f has a zero of multiplicity 2 at x = 0. 𝑓 π‘₯ = 𝑒 π‘₯ βˆ’π‘₯βˆ’1 Newton’s method are shown in Table The sequence is clearly converging to 0, but not quadratically.

10 modification of Newton’s method
Some Comments on Root finding modification of Newton’s method Example: Show that f has a zero of multiplicity 2 at x = 0. 𝑓 π‘₯ = 𝑒 π‘₯ βˆ’π‘₯βˆ’1 If p is a zero of f of multiplicity m 𝑓 π‘₯ = (π‘₯βˆ’π‘) π‘š π‘ž π‘₯ then p is a zero of 𝑓′ of multiplicity m-1 Hence p is a simple zero of ΞΌ π‘₯ = 𝑓(π‘₯) 𝑓′(π‘₯) Newton’s method can then be applied to ΞΌ π‘₯ The only drawback to this method is the additional calculation of

11 modification of Newton’s method
Some Comments on Root finding modification of Newton’s method Example: Show that f has a zero of multiplicity 2 at x = 0. 𝑓 π‘₯ = 𝑒 π‘₯ βˆ’π‘₯βˆ’1 If p is a zero of f of multiplicity m 𝑓 π‘₯ = (π‘₯βˆ’π‘) π‘š π‘ž π‘₯ then p is also a fixed point of 𝑔 π‘₯ =π‘₯βˆ’π‘š 𝑓(π‘₯) 𝑓′(π‘₯) π‘₯ 𝑛+1 = π‘₯ 𝑛 βˆ’π‘š 𝑓( π‘₯ 𝑛 ) 𝑓′( π‘₯ 𝑛 )

12 Nonlinear system of equations:
Some Comments on Root finding Nonlinear system of equations: 𝑓 1 =π‘₯ π‘₯ 2 + π‘₯ 3 2 βˆ’8 𝑓 2 =2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 βˆ’11 𝑓 3 =π‘₯ π‘₯ π‘₯ 3 2 βˆ’14 π‘₯ π‘₯ 2 + π‘₯ 3 2 =8 2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 =11 π‘₯ π‘₯ π‘₯ 3 2 =14 Convert into 𝐹 𝑋 =0 𝐹 𝑋 = π‘₯ π‘₯ 2 + π‘₯ 3 2 βˆ’8 2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 βˆ’11 π‘₯ π‘₯ π‘₯ 3 2 βˆ’14 π‘₯ π‘₯ 2 + π‘₯ 3 2 βˆ’8=0 2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 βˆ’11=0 π‘₯ π‘₯ π‘₯ 3 2 βˆ’14=0 𝑋= π‘₯ 1 π‘₯ 2 π‘₯ 3

13 Some Comments on Root finding
Def: Jacobian Matrix 𝐹 𝑋 = π‘₯ π‘₯ 2 + π‘₯ 3 2 βˆ’8 2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 βˆ’11 π‘₯ π‘₯ π‘₯ 3 2 βˆ’14 𝐽 𝑋 = πœ• 𝑓 1 π‘₯ 1 πœ• 𝑓 1 π‘₯ 2 πœ• 𝑓 1 π‘₯ 3 πœ• 𝑓 2 π‘₯ 1 πœ• 𝑓 2 π‘₯ 2 πœ• 𝑓 2 π‘₯ 3 πœ• 𝑓 3 π‘₯ 1 πœ• 𝑓 3 π‘₯ 2 πœ• 𝑓 3 π‘₯ 3 𝑋= π‘₯ 1 π‘₯ 2 π‘₯ 3 Example: 𝐽 𝑋 = 2 π‘₯ π‘₯ π‘₯ 2 2 βˆ’1 2 π‘₯ 1 2 π‘₯ 2 2 π‘₯ 3 Example: 𝑋 (0) = 1 βˆ’1 1 𝐽 𝑋 (0) = βˆ’1 2 βˆ’2 2

14 𝑋 (𝑛+1) = 𝑋 (𝑛) βˆ’ 𝐽 ( 𝑋 (𝑛) ) βˆ’πŸ 𝑓( 𝑋 (𝑛) )
Some Comments on Root finding Newton’s method for single variable π‘₯ 𝑛+1 = π‘₯ 𝑛 βˆ’ 𝑓( π‘₯ 𝑛 ) 𝑓′( π‘₯ 𝑛 ) π‘₯ 𝑛+1 = π‘₯ 𝑛 βˆ’ 𝑓′( π‘₯ 𝑛 ) βˆ’πŸ 𝑓( π‘₯ 𝑛 ) Newton’s method for system of nonlinear equations 𝐹 𝑋 =0 𝑋 (𝑛+1) = 𝑋 (𝑛) βˆ’ 𝐽 ( 𝑋 (𝑛) ) βˆ’πŸ 𝑓( 𝑋 (𝑛) ) 𝑋 (𝑛) = π‘₯ 1 (𝑛) π‘₯ 2 (𝑛) π‘₯ 3 (𝑛)

15 π‘¨π‘Œ 𝑛 =𝑏 Newton’s method for system of nonlinear equations 𝐹 𝑋 =0
Some Comments on Root finding Newton’s method for system of nonlinear equations 𝐹 𝑋 =0 𝑋 (𝑛+1) = 𝑋 (𝑛) βˆ’ 𝐽 ( 𝑋 (𝑛) ) βˆ’πŸ 𝑓( 𝑋 (𝑛) ) 𝑋 (𝑛) = π‘₯ 1 (𝑛) π‘₯ 2 (𝑛) π‘₯ 3 (𝑛) 𝑋 (𝑛+1) βˆ’ 𝑋 𝑛 =βˆ’ 𝐽 ( 𝑋 (𝑛) ) βˆ’πŸ 𝑓( 𝑋 (𝑛) ) 𝑋 (𝑛+1) βˆ’ 𝑋 𝑛 = 𝐽 𝑋 𝑛 βˆ’πŸ (βˆ’π‘“ 𝑋 𝑛 ) π‘Œ 𝑛 = 𝐽 𝑋 𝑛 βˆ’πŸ (βˆ’π‘“ 𝑋 𝑛 ) 𝐽 𝑋 𝑛 π‘Œ 𝑛 = βˆ’π‘“ 𝑋 𝑛 π‘¨π‘Œ 𝑛 =𝑏 This is a linear system of n-equations in n-unknowns where 𝐴=𝐽 𝑋 𝑛 𝒂𝒏𝒅 𝑏= βˆ’π‘“ 𝑋 𝑛

16 ALGORITHM: (Newton’s method for system of nonlinear equations)
Some Comments on Root finding ALGORITHM: (Newton’s method for system of nonlinear equations) 𝐹= π‘₯ π‘₯ 2 + π‘₯ 3 2 βˆ’8 2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 βˆ’11 π‘₯ π‘₯ π‘₯ 3 2 βˆ’14 𝐽 𝑋 = 2 π‘₯ π‘₯ π‘₯ 2 2 βˆ’1 2 π‘₯ 1 2 π‘₯ 2 2 π‘₯ 3 𝑿 (𝟎) = 𝒙 𝟏 (𝟎) 𝒙 𝟐 (𝟎) 𝒙 πŸ‘ (𝟎) 𝑋 (0) = 1 βˆ’1 1 Given initial guess 𝐽 𝑋 (0) = βˆ’1 2 βˆ’2 2 1) Calculate Jacobian Matrix 𝑨= 𝑱 𝑿 (𝟎) 𝑏= βˆ’7 βˆ’7 βˆ’13 2) Calculate right-hand-side vector 𝒃= βˆ’π’‡ 𝑿 𝟎 βˆ’1 2 βˆ’ 𝑦 1 (0) 𝑦 2 (0) 𝑦 3 (0) = βˆ’7 βˆ’7 βˆ’13 β†’ 𝑦 1 (0) 𝑦 2 (0) 𝑦 3 (0) = 19/18 βˆ’4/3 28/9 3) Solve the linear system: 𝑨𝒀 𝟎 =𝒃 4) update 𝑋 (1) = βˆ’ 𝑿 (𝟎) = 𝑿 (𝟎) + 𝒀 (𝟎) Repeat (1 - 4)

17 Some Comments on Root finding
clear; clc f [ x(1)^2+x(2)+… x(3)^2-8;2*x(1)+3*x(2)^2-x(3)-11; x(1)^2+x(2)^2+x(3)^2-14]; x=[1;-1;1]; format short for n=1:10 [J] = jacob(x); F = - f(x); y = J\F x = x + y end x function [J] = jacob(x); J=[ 2*x(1) *x(3); ... *x(2) ; … 2*x(1) 2*x(2) *x(3)]; 1 2 3 4 n 𝒙 𝟏 (𝒏) 𝒙 𝟐 (𝒏) 𝒙 πŸ‘ (𝒏) π‘₯ π‘₯ 2 + π‘₯ 3 2 =8 2π‘₯ π‘₯ 2 2 βˆ’ π‘₯ 3 =11 π‘₯ π‘₯ π‘₯ 3 2 =14


Download ppt "Some Comments on Root finding"

Similar presentations


Ads by Google