The Bisection Method. Introduction Bisection Method: Bisection Method = a numerical method in Mathematics to find a root of a given function.

Slides:



Advertisements
Similar presentations
Bisection Method (Midpoint Method for Equations).
Advertisements

Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
Solution of Nonlinear Equations: Lecture (I)
Chapter 11 Recursion Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Fin500J: Mathematical Foundations in Finance Topic 3: Numerical Methods for Solving Non-linear Equations Philip H. Dybvig Reference: Numerical Methods.
- + Suppose f(x) is a continuous function of x within interval [a, b]. f(a) = - ive and f(b) = + ive There exist at least a number p in [a, b] with f(p)
Nested conditional statements. Previously discussed Conditional statements discussed so far: Syntax of the if-statement: if-statement if-else-statement.
The switch statement: an N-way selection statement.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
Using the Java programming language compiler. Review of relevant material from previous lectures From previous lectures: A computer can only execute machine.
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
The break and continue statements. Introduction There are 2 special statements that can affect the execution of loop statements (such as a while-statement)
Shorthand operators.
Roots of Equations Chapter 3. Roots of Equations Also called “zeroes” of the equation –A value x such that f(x) = 0 Extremely important in applications.
I. Finding Roots II. Integrating Functions
Solving Non-Linear Equations (Root Finding)
The character data type char
Continuity ( Section 1.8) Alex Karassev. Definition A function f is continuous at a number a if Thus, we can use direct substitution to compute the limit.
Chapter 6 Finding the Roots of Equations
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
The Rectangle Method. Introduction Definite integral (High School material): A definite integral a ∫ b f(x) dx is the integral of a function f(x) with.
Parameter passing mechanism: pass-by-value. Introduction In the last webpage, we discussed how to pass information to a method I have kept it (deliberately)
The dangling-else ambiguity. Previously discussed The Java compiler (translator) consider white space characters (i.e., SPACE, TAB and New line) as insignificant.
Lecture 3 Numerical Analysis. Solution of Non-Linear Equations Chapter 2.
What does a computer program look like: a general overview.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
Working with arrays (we will use an array of double as example)
Introduction to programming in the Java programming language.
CSC 211 Data Structures Lecture 13
Assignment statements using the same variable in LHS and RHS.
Mixing integer and floating point numbers in an arithmetic operation.
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
Integer numerical data types. The integer data types (multiple !) The integer data types use the binary number system as encoding method There are a number.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
Solving Non-Linear Equations (Root Finding)
MAT 4725 Numerical Analysis Section 2.1 The Bisection Method
Solution of Nonlinear Equations Topic: Bisection method
Numerical Methods Solution of Equation.
Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
The while-statement. The loop statements in Java What is a loop-statement: A loop-statement is a statement that repeatedly executes statements contained.
Arithmetic expressions containing Mathematical functions.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Recursive Methods for Finding Roots of Functions Bisection & Newton’s Method.
Working with floating point expressions. Arithmetic expressions Using the arithmetic operators: and brackets (... ), we can construct arithmetic expression.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Simple algorithms on an array - compute sum and min.
The ++ and -- expressions. The ++ and -- operators You guessed it: The ++ and -- are operators that return a value.
The if-else statement. Introducing the if-else statement Programming problem: Re-write the a,b,c-formula program to solve for complex number solutions.
CSE 330: Numerical Methods. What is true error? True error is the difference between the true value (also called the exact value) and the approximate.
Numerical Calculation Part 1: Equations &Roots Dr.Entesar Ganash (Bisection's Method)
MATH342: Numerical Analysis Sunjae Kim.
Solution of Nonlinear Equations (Root finding Problems
Numerical Methods and Analysis
The Boolean (logical) data type boolean
Java Intro.
Intermediate Value Theorem
Intermediate Value Theorem
1.4 Continuity and One-Sided Limits (Part 2)
Continuity Alex Karassev.
CIS 110: Introduction to Computer Programming
The for-statement.
Local variables and how to recognize them
Solutions for Nonlinear Equations
Presentation transcript:

The Bisection Method

Introduction Bisection Method: Bisection Method = a numerical method in Mathematics to find a root of a given function

Introduction (cont.) Root of a function: Root of a function f(x) = a value a such that: f(a) = 0

Introduction (cont.) Example: Function: f(x) = x Roots: x = -2, x = 2 Because: f(-2) = (-2) = = 0 f(2) = (2) = = 0

A Mathematical Property Well-known Mathematical Property: If a function f(x) is continuous on the interval [a..b] and sign of f(a) ≠ sign of f(b), then There is a value c ∈ [a..b] such that: f(c) = 0 I.e., there is a root c in the interval [a..b]

A Mathematical Property (cont.) Example:

The Bisection Method The Bisection Method is a successive approximation method that narrows down an interval that contains a root of the function f(x) The Bisection Method is given an initial interval [a..b] that contains a root (We can use the property sign of f(a) ≠ sign of f(b) to find such an initial interval) The Bisection Method will cut the interval into 2 halves and check which half interval contains a root of the function The Bisection Method will keep cut the interval in halves until the resulting interval is extremely small The root is then approximately equal to any value in the final (very small) interval.

The Bisection Method (cont.) Example: Suppose the interval [a..b] is as follows:

The Bisection Method (cont.) We cut the interval [a..b] in the middle: m = (a+b)/2

The Bisection Method (cont.) Because sign of f(m) ≠ sign of f(a), we proceed with the search in the new interval [a..b]:

The Bisection Method (cont.) We can use this statement to change to the new interval: b = m;

The Bisection Method (cont.) In the above example, we have changed the end point b to obtain a smaller interval that still contains a root In other cases, we may need to changed the end point b to obtain a smaller interval that still contains a root

The Bisection Method (cont.) Here is an example where you have to change the end point a: Initial interval [a..b]:

The Bisection Method (cont.) After cutting the interval in half, the root is contained in the right-half, so we have to change the end point a:

The Bisection Method (cont.) Rough description (pseudo code) of the Bisection Method: Given: interval [a..b] such that: sign of f(a) ≠ sign of f(b) repeat (until the interval [a..b] is "very small") { a+b m = -----; // m = midpoint of interval [a..b] 2 if ( sign of f(m) ≠ sign of f(b) ) { use interval [m..b] in the next iteration

The Bisection Method (cont.) (i.e.: replace a with m) } else { use interval [a..m] in the next iteration (i.e.: replace b with m) } Approximate root = (a+b)/2; (any point between [a..b] will do because the interval [a..b] is very small)

The Bisection Method (cont.) Structure Diagram of the Bisection Algorithm:

The Bisection Method (cont.) Example execution: We will use a simple function to illustrate the execution of the Bisection Method Function used: Roots: √3 = and −√3 = − f(x) = x 2 - 3

The Bisection Method (cont.) We will use the starting interval [0..4] since: The interval [0..4] contains a root because: sign of f(0) ≠ sign of f(4) f(0) = 0 2 − 3 = −3 f(4) = 4 2 − 3 = 13

The Bisection Method (cont.) Steps taken by the Bisection Method: Iteration 1: New interval: [0..2] (it contains √3 = !!!)

The Bisection Method (cont.) Iteration 2: New interval: [1..2] (it contains √3 = !!!)

The Bisection Method (cont.) Iteration 3: New interval: [ ] (it contains √3 = !!!)

The Bisection Method (cont.) And so on Result: The interval gets smaller and smaller But it will always contain the root √3 When the interval is smaller than , the while-loop will exit At that moment, the end points of the interval will be very close to root √3

The Bisection Method (cont.) Java program: // Bisection Method - Solves: x^2 - 3 = 0 public class Bisection01 { public static void main(String[] args) { final double epsilon = ; double a, b, m, y_m, y_a; a = 0; b = 4; while ( (b-a) > epsilon ) { m = (a+b)/2; // Mid point

The Bisection Method (cont.) y_m = m*m - 3.0; // y_m = f(m) y_a = a*a - 3.0; // y_a = f(a) if ( (y_m > 0 && y_a 0) ) { // f(a) and f(m) have different signs: move b b = m; } else { // f(a) and f(m) have same signs: move a a = m; } System.out.println("New interval: [" + a + ".. " + b + "]"); // Print progress } System.out.println("Approximate solution = " + (a+b)/2 ); }

The Bisection Method (cont.) Output: Initial interval: [ ] New interval: [ ](We did the first 3 by hand above) New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] New interval: [ ] Approximate solution =

The Bisection Method (cont.) Example Program: (Demo above code) –Prog file: Bisection01.java How to run the program: Right click on link and save in a scratch directory To compile: javac Bisection01.java To run: java Bisection01

Finding the roots of a different function Suppose we want to find the root of in the interval [0..4] f(x) = x 3 + x - 3

Finding the roots of a different function (cont.) Changes to the Java program: // Solves: x^3 + x - 3 = 0 public class Bisection02 { public static void main(String[] args) { final double epsilon = ; double a, b, m, y_m, y_a; a = 0; b = 4; while ( (b-a) > epsilon ) { m = (a+b)/2; // Mid point

Finding the roots of a different function (cont.) y_m = m*m*m + m - 3.0; // y_m = f(m) y_a = a*a*a + a - 3.0; // y_a = f(a) if ( (y_m > 0 && y_a 0) ) { // f(a) and f(m) have different signs: move b b = m; } else { // f(a) and f(m) have same signs: move a a = m; } System.out.println("New interval: [" + a + ".. " + b + "]"); } System.out.println("Approximate solution = " + (a+b)/2 ); }

Finding the roots of a different function (cont.) Example Program: (Demo above code) –Prog file: Bisection02.java How to run the program: Right click on link and save in a scratch directory To compile: javac Bisection02.java To run: java Bisection02

Finding the roots of a different function (cont.) We had to change the body of the Java program to find the root of a different function This is very inconvenient It would be more convenient to if we can write: y_m = f(m); y_a = f(a);

Finding the roots of a different function (cont.) When we solve a different function, we make changes to the function definition f() This is indeed possible in Java... However, we have not study user-defined methods yet. But we will get there very soon.