Some Comments on Root finding

Slides:



Advertisements
Similar presentations
Complex Numbers; Quadratic Equations in the Complex Number System
Advertisements

Lecture 5 Newton-Raphson Method
Numerical Solution of Nonlinear Equations
ROOTS OF EQUATIONS Student Notes ENGR 351 Numerical Methods for Engineers Southern Illinois University Carbondale College of Engineering Dr. L.R. Chevalier.
Basics A quadratic equation is an equation equivalent to an equation of the type ax2 + bx + c = 0, where a is nonzero We can solve a quadratic equation.
MTH 065 Elementary Algebra II
Solving Quadratic Equations by Factoring Algebra I.
Systems of Non-Linear Equations
NUMERICAL METHODS WITH C++ PROGRAMMING
Using the Quadratic Formula to Solve a Quadratic Equation
8/24/2015 V. J. Motto 1 Chapter 2: Review – Quadratic Function V. J. Motto M110 Modeling with Elementary Functions.
Quadratics       Solve quadratic equations using multiple methods: factoring, graphing, quadratic formula, or square root principle.
3.7 Graphs of Rational Functions
3.5 Quadratic Equations OBJ:To solve a quadratic equation by factoring.
ITERATIVE TECHNIQUES FOR SOLVING NON-LINEAR SYSTEMS (AND LINEAR SYSTEMS)
1.3 Solving Equations Using a Graphing Utility; Solving Linear and Quadratic Equations.
Newton's Method for Functions of Several Variables Joe Castle & Megan Grywalski.
OBJ: To solve a quadratic equation by factoring
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Roots of Equations ~ Open Methods Chapter 6 Credit:
CHAPTER 3 NUMERICAL METHODS
1.5 – Day 1 Equations.
Newton’s Method, Root Finding with MATLAB and Excel
linear  2.3 Newton’s Method ( Newton-Raphson Method ) 1/12 Chapter 2 Solutions of Equations in One Variable – Newton’s Method Idea: Linearize a nonlinear.
5-5 Solving Quadratic Equations Objectives:  Solve quadratic equations.
Solving Non-Linear Equations (Root Finding)
1 Copyright © Cengage Learning. All rights reserved. 2. Equations and Inequalities 2.3 Quadratic Equations.
Solving Quadratic Equations. Factor: x² - 4x - 21 x² -21 a*c = -21 b = -4 x + = -21 = x 3x3x x 3 (GCF) x-7 (x – 7)(x + 3)
Lecture 6 - Single Variable Problems & Systems of Equations CVEN 302 June 14, 2002.
Lesson 6.5: The Quadratic Formula and the Discriminant, pg. 313 Goals: To solve quadratic equations by using the Quadratic Formula. To use the discriminant.
Lecture 4 Numerical Analysis. Solution of Non-Linear Equations Chapter 2.
CSE 330: Numerical Methods. Introduction The bisection and false position method require bracketing of the root by two guesses Such methods are called.
Copyright © Cengage Learning. All rights reserved. Fundamentals.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 / Chapter 5.
Linear Equations in One Variable
CHAPTER 3 NUMERICAL METHODS
The Quadratic Formula..
10 Quadratic Equations.
Chapter 4 Quadratic Equations
The Quadratic Formula..
Objectives Solve quadratic equations by factoring.
Numerical Methods and Analysis
Quadratic Equations and Problem Solving
Solving Quadratic Functions
What is an equation? An equation is the equality of two different expressions. This equality is true only for a number of dinstinct values (or none) of.
5.8 Rational Zero Theorem.
Definition of a Polynomial Inequality
CHAPTER R: Basic Concepts of Algebra
QUADRATIC EQUATIONS MSJC ~ San Jacinto Campus
Solving Quadratic Functions
5.6 – The Quadratic Formula And Ch 5 Review
Chapter 6.
Computers in Civil Engineering 53:081 Spring 2003
Sec. 1.4 Quadratic Equations.
Solving Quadratic Equations by Factoring
Copyright © Cengage Learning. All rights reserved.
SOLUTION OF NONLINEAR EQUATIONS
Review: Simplify.
Newton’s Method and Its Extensions
Chapter 6 Section 5.
Example 1 – Solving a Trigonometric Equation
Sec:5.2 The Bisection Method.
The Quadratic Formula..
Fixed- Point Iteration
Chapter 6.
The Quadratic Formula..
Numerical Analysis – Solving Nonlinear Equations
Solving Equations by Factoring
Pivoting, Perturbation Analysis, Scaling and Equilibration
Presentation transcript:

Some Comments on Root finding

Avoid subtraction of nearly equal numbers Some Comments on Root finding Consider the following two numbers a= 0.123456789012345678; b= 0.123456789012345677; c = a - b 0.123456789012345678 - 0.123456789012345677 ans = 0.000000000000000001 Avoid subtraction of nearly equal numbers a=1e-16; b=1; c=-1; a+(b+c) (a+b)+c Associative property 𝑎+ 𝑏+𝑐 = 𝑎+𝑏 +𝑐 ans = 1.000000000000000e-16 why

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) x*(a*x+b)+c; xeps = 1e-8; b = (2/xeps) + xeps; a=1; c=1; f = @(x) 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 = -5.000000000000000e-09 ans = 100 𝑥 1 = −2𝑐 𝑏+ 𝑏 2 −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.

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

Some Comments on Root finding Cq1 solution Cq2 solution

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 − 𝑥 𝑛 0 2.0000000000 1 1.3034338465 6.9656615347e-01 2 1.3449403509 4.1506504376e-02 3 1.3447510489 1.8930200914e-04 4 1.3447510454 3.5169049895e-09

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

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.

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

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 = 𝑥 𝑛 −𝑚 𝑓( 𝑥 𝑛 ) 𝑓′( 𝑥 𝑛 )

Nonlinear system of equations: Some Comments on Root finding Nonlinear system of equations: 𝑓 1 =𝑥 1 2 + 𝑥 2 + 𝑥 3 2 −8 𝑓 2 =2𝑥 1 + 3𝑥 2 2 − 𝑥 3 −11 𝑓 3 =𝑥 1 2 + 𝑥 2 2 + 𝑥 3 2 −14 𝑥 1 2 + 𝑥 2 + 𝑥 3 2 =8 2𝑥 1 + 3𝑥 2 2 − 𝑥 3 =11 𝑥 1 2 + 𝑥 2 2 + 𝑥 3 2 =14 Convert into 𝐹 𝑋 =0 𝐹 𝑋 = 𝑥 1 2 + 𝑥 2 + 𝑥 3 2 −8 2𝑥 1 + 3𝑥 2 2 − 𝑥 3 −11 𝑥 1 2 + 𝑥 2 2 + 𝑥 3 2 −14 𝑥 1 2 + 𝑥 2 + 𝑥 3 2 −8=0 2𝑥 1 + 3𝑥 2 2 − 𝑥 3 −11=0 𝑥 1 2 + 𝑥 2 2 + 𝑥 3 2 −14=0 𝑋= 𝑥 1 𝑥 2 𝑥 3

Some Comments on Root finding Def: Jacobian Matrix 𝐹 𝑋 = 𝑥 1 2 + 𝑥 2 + 𝑥 3 2 −8 2𝑥 1 + 3𝑥 2 2 − 𝑥 3 −11 𝑥 1 2 + 𝑥 2 2 + 𝑥 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 𝑥 1 1 2 𝑥 3 2 6 𝑥 2 2 −1 2 𝑥 1 2 𝑥 2 2 𝑥 3 Example: 𝑋 (0) = 1 −1 1 𝐽 𝑋 (0) = 2 1 2 2 6 −1 2 −2 2

𝑋 (𝑛+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 (𝑛)

𝑨𝑌 𝑛 =𝑏 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 𝐴=𝐽 𝑋 𝑛 𝒂𝒏𝒅 𝑏= −𝑓 𝑋 𝑛

ALGORITHM: (Newton’s method for system of nonlinear equations) Some Comments on Root finding ALGORITHM: (Newton’s method for system of nonlinear equations) 𝐹= 𝑥 1 2 + 𝑥 2 + 𝑥 3 2 −8 2𝑥 1 + 3𝑥 2 2 − 𝑥 3 −11 𝑥 1 2 + 𝑥 2 2 + 𝑥 3 2 −14 𝐽 𝑋 = 2 𝑥 1 1 2 𝑥 3 2 6 𝑥 2 2 −1 2 𝑥 1 2 𝑥 2 2 𝑥 3 𝑿 (𝟎) = 𝒙 𝟏 (𝟎) 𝒙 𝟐 (𝟎) 𝒙 𝟑 (𝟎) 𝑋 (0) = 1 −1 1 Given initial guess 𝐽 𝑋 (0) = 2 1 2 2 6 −1 2 −2 2 1) Calculate Jacobian Matrix 𝑨= 𝑱 𝑿 (𝟎) 𝑏= −7 −7 −13 2) Calculate right-hand-side vector 𝒃= −𝒇 𝑿 𝟎 2 1 2 2 6 −1 2 −2 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) = 2.0556 −2.333 4.111 𝑿 (𝟎) = 𝑿 (𝟎) + 𝒀 (𝟎) Repeat (1 - 4)

Some Comments on Root finding clear; clc f = @(x) [ 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) 1 2*x(3); ... 2 6*x(2) -1 ; … 2*x(1) 2*x(2) 2*x(3)]; 1 2 3 4 n 𝒙 𝟏 (𝒏) 𝒙 𝟐 (𝒏) 𝒙 𝟑 (𝒏) 2.0556 -2.3333 4.1111 1.1387 -2.0196 3.2187 1.0045 -2.0001 3.0088 1.0000 -2.0000 3.0000 𝑥 1 2 + 𝑥 2 + 𝑥 3 2 =8 2𝑥 1 + 3𝑥 2 2 − 𝑥 3 =11 𝑥 1 2 + 𝑥 2 2 + 𝑥 3 2 =14