Topic 3 Lesson 9

AUB Moodle Videos
4 Jan 202313:07

Summary

TLDRThis lesson introduces the Bisection method for approximating square roots of numbers between 0 and 1, avoiding the power operator due to floating-point inaccuracies. The method efficiently narrows the search interval by halving it with each iteration, aiming for an approximation error less than a given tolerance, epsilon. The script explains the iterative process, provides a Python code example, and compares the Bisection method's efficiency to Heron's method, highlighting its straightforward convergence analysis.

Takeaways

  • 📚 The lesson focuses on the Bisection method, a numerical technique used to approximate the square root of a given number.
  • 🔢 It is assumed that the number \( x \) is non-negative and less than or equal to 1, ensuring the square root is between \( x \) and 1.
  • 📉 The method avoids using the power operator and instead relies on the properties of the square root function within the given interval.
  • 🔍 The goal is to find an approximation \( p \) such that \( |p^2 - x| < \epsilon \), where \( \epsilon \) is a given tolerance (e.g., \( 10^{-6} \)).
  • 🚫 A brute force approach would involve checking many points, which is inefficient and slow.
  • 🔄 The Bisection method improves efficiency by examining the midpoint of the interval and narrowing the search based on whether the midpoint squared is less than or greater than \( x \).
  • 🔢 The midpoint is calculated as \( \text{mid} = \frac{\text{low} + \text{high}}{2} \), where \( \text{low} \) and \( \text{high} \) are the current bounds of the search interval.
  • 🔎 The method iteratively halves the search interval, significantly reducing the number of steps needed to achieve the desired accuracy.
  • 📉 The error approximation decreases exponentially with each iteration, making the Bisection method highly efficient for finding square roots.
  • 📚 The lesson also mentions Heron's method, which has a faster convergence rate but is less straightforward to analyze compared to the Bisection method.

Q & A

  • What is the main topic of the lesson?

    -The main topic of the lesson is the Bisection method, specifically its application in approximating the square root of a given number.

  • Why is it assumed that the number x is less than or equal to 1?

    -It is assumed that x is less than or equal to 1 for simplicity, ensuring that the square root of x is between x and 1, which makes the problem more manageable.

  • What is the significance of the intersection point between y=sqrt(x) and y=x?

    -The intersection point between y=sqrt(x) and y=x is significant because it indicates that for x values between 0 and 1, the square root of x will also be between x and 1.

  • Why is the brute force iterative approach considered slow?

    -The brute force iterative approach is considered slow because it involves dividing the interval between x and 1 into many points and traversing them one by one, potentially requiring a large number of steps.

  • What is the main idea behind the Bisection method?

    -The main idea behind the Bisection method is to examine the middle element of the interval between x and 1, compare it with the square root of x, and then narrow down the search interval based on the comparison, effectively bisecting the search space at each iteration.

  • How does the Bisection method improve efficiency compared to the brute force approach?

    -The Bisection method improves efficiency by reducing the search interval length by half at each iteration, thus quickly narrowing down the possible values for the square root.

  • What is the stopping condition for the while loop in the Bisection method algorithm?

    -The stopping condition for the while loop is when the absolute value of (mid*mid - x) is less than or equal to epsilon, indicating that the approximation is within the desired tolerance.

  • How does the Bisection method handle the case when mid*mid is less than x?

    -When mid*mid is less than x, the method updates the lower bound of the search interval (low) to mid, effectively narrowing the search to the interval between mid and high.

  • How does the Bisection method handle the case when mid*mid is greater than x?

    -When mid*mid is greater than x, the method updates the upper bound of the search interval (high) to mid, effectively narrowing the search to the interval between low and mid.

  • What is the relationship between the number of iterations and the approximation error in the Bisection method?

    -The approximation error decreases exponentially with the number of iterations. After k iterations, the error is at most (1/2^(k+1)), which shows that the method can quickly reduce the error to a very small value.

  • How does the Bisection method compare to Heron's method in terms of convergence rate?

    -While Heron's method has a faster convergence rate, its convergence analysis is less trivial than that of the Bisection method, which is more straightforward and easier to understand.

Outlines

00:00

🔍 Introduction to the Bisection Method for Square Root Approximation

This paragraph introduces the Bisection method, a numerical technique used for approximating the square root of a non-negative real number 'x' that is less than or equal to 1. The method avoids using the power operator and assumes that the square root of 'x' lies between 'x' and 1. It discusses the limitations due to floating point representation and the acceptable level of accuracy defined by a tolerance parameter 'epsilon'. The paragraph also contrasts the Bisection method with a brute force approach, highlighting the efficiency of the former by iteratively narrowing down the search interval and dividing the interval length by 2 with each iteration.

05:01

📝 Algorithm Translation to Python Code for Bisection Method

The second paragraph translates the Bisection method algorithm into Python code. It explains the initialization of variables 'low' and 'high' to represent the search interval, with 'mid' calculated as their average. A while loop is used with a stopping condition based on the difference between 'mid' squared and 'x'. The body of the loop includes conditional statements to update 'low' or 'high' based on whether 'mid' squared is less than or greater than 'x', ensuring the search interval is narrowed down correctly. The paragraph also discusses the importance of updating 'mid' to avoid an infinite loop and concludes with a practical example using 'x' as 0.5 and 'epsilon' as 0.01, demonstrating the iterative process of narrowing down to the approximate square root.

10:02

📉 Analysis of the Bisection Method's Efficiency and Comparison with Other Methods

The final paragraph delves into the efficiency of the Bisection method by analyzing the decrease in the search interval's length after each iteration, which is halved exponentially. It provides a formula for the interval length after 'k' iterations and estimates the approximation error, which is the maximum distance between 'mid' and the actual square root of 'x'. The error is shown to decrease with each iteration, capped by the reciprocal of 2 raised to the power of 'k+1'. The paragraph concludes by comparing the Bisection method with Heron's method, noting that while Heron's method may have a faster convergence rate, the Bisection method's convergence analysis is more straightforward. It also mentions that the Bisection method, also known as binary search, will be applied to discrete problems later in the course.

Mindmap

Keywords

💡Bisection method

The Bisection method is a numerical technique used to find an approximate solution to equations where finding an exact solution is difficult. In the context of the video, it is applied to approximate the square root of a given number. The method involves repeatedly halving the interval between a known lower and upper bound until the desired accuracy is achieved. The script illustrates this by narrowing down the search for the square root of a number between 0 and 1, using the midpoint of the interval and halving the range until the midpoint squared is close enough to the original number.

💡Square root

The square root of a number is a value that, when multiplied by itself, gives the original number. In the script, the focus is on approximating the square root of a non-negative real number less than or equal to 1. The video emphasizes the importance of this concept by explaining that the square root of a number x is between x and 1, and the Bisection method is used to approximate this value.

💡Floating point representation

Floating point representation refers to the way computers store and manipulate real numbers, which is limited by the number of bytes used. In the script, it is mentioned that due to the limited accuracy of this representation, the Bisection method is used to find an approximation of the square root that is within a certain tolerance, rather than the exact square root.

💡Tolerance parameter (epsilon)

Epsilon is a small positive number used to define the acceptable level of error in an approximation. In the video, epsilon is used as the tolerance parameter to determine when the approximation of the square root is close enough to the actual value. The script specifies that the approximation is acceptable if the absolute difference between the square of the approximation and the original number is less than epsilon, such as 10 to the power of -6.

💡Iterative approach

An iterative approach is a method of solving problems by repeating a process or calculation until a certain condition is met. The script describes a brute force iterative method where the interval between the number and 1 is divided into many points, and the method checks each point to find an approximation of the square root. However, this approach is criticized for being slow and inefficient.

💡Midpoint

The midpoint, or 'mid' in the script, is the average of the lower and upper bounds of the interval being considered. It is used in the Bisection method to determine the next point of interest in the search for the square root. The script explains that by comparing the square of the midpoint with the original number, the method can decide whether to narrow the search to the left or right half of the interval.

💡Interval

In the context of the Bisection method, an interval refers to the range of values between a lower and upper bound within which the solution is sought. The script describes how the interval is initially set between the given number and 1, and then repeatedly halved to narrow down the search for the square root.

💡Convergence rate

The convergence rate of an algorithm refers to how quickly it approaches the solution as iterations progress. The script mentions that while the Bisection method has a slower convergence rate compared to other methods like Heron's method, its convergence is more straightforward to analyze, making it a preferred choice for certain applications.

💡Binary search

Binary search is another term for the Bisection method, especially when applied to discrete problems such as searching for a specific value in a sorted list. The script notes that the Bisection method, also known as binary search, is efficient because it halves the search interval with each iteration, quickly reducing the error in the approximation.

💡Approximation error

Approximation error is the difference between the approximate value and the actual value. In the script, the approximation error is discussed in terms of how it decreases with each iteration of the Bisection method. It is calculated as the length of the search interval divided by 2, which becomes smaller with each iteration, indicating that the method quickly converges to the true square root.

Highlights

The lesson focuses on the Bisection method for approximating the square root of a given number.

Assumption made that the number x is between 0 and 1, ensuring the square root of x is between x and 1.

Floating point representation with limited accuracy is used, requiring an acceptable tolerance level.

The brute force iterative approach is slow, involving dividing the interval into many points and checking each one.

The Bisection method is introduced as a more efficient alternative to the brute force approach.

The Bisection method involves examining the middle element of the interval and comparing it with the square root of x.

If the middle element squared is close enough to x, it is considered a good approximation of the square root.

The method narrows down the search interval based on whether the middle element squared is less than or greater than x.

The search interval length is halved with each iteration, making the Bisection method very efficient.

The algorithm is translated into Python code, demonstrating how to implement the Bisection method programmatically.

Variables low and high are used to track the search interval, with mid initialized to their average.

A while loop is used with a condition based on the absolute value of (mid*mid - x) being greater than epsilon.

The search interval is updated based on whether mid squared is less than or greater than x.

The mid variable is updated after updating low and high to avoid an infinite loop.

The approximate square root is printed when the condition is no longer met, indicating a close enough approximation.

An example is provided where x = 0.5 and epsilon = 0.01, demonstrating the iterative process of the Bisection method.

The speed and efficiency of the Bisection method are analyzed, showing how the search interval length decreases exponentially.

The approximation error is estimated, showing that it decreases with each iteration.

A comparison is made with Heron's method, noting that while it may have a faster convergence rate, its analysis is less straightforward.

The Bisection method, also known as binary search, is highlighted for its applicability in both numerical and discrete problems.

Transcripts

play00:00

In this lesson, we will study the

play00:02

Bisection method illustrated on

play00:04

the problem of approximating the

play00:06

square root of a given number.

play00:09

Given a non negative real number x we would

play00:11

like to approximate its square root,

play00:13

without using the power operator star star.

play00:18

For simplicity, we are going to assume

play00:21

that x is less than or equal to 1.

play00:26

So x is a number between 0 and 1,

play00:29

so that square root of x is between x and

play00:33

1, and this is the case because if

play00:38

you look at the curve of the function,

play00:42

this is square root of x and

play00:45

this is y = x. They intersect here.

play00:49

This is 1 and this is 1.

play00:51

So if x is between 0 and 1.

play00:56

This is x.

play00:58

This is square root of x.

play01:01

Square root of x is between x and

play01:04

1 and we're not after the square

play01:07

root exactly because we're using

play01:11

the floating point representation,

play01:14

which is 8 byte and it has limited accuracy,

play01:17

so we have to accept certain accuracy.

play01:21

We're OK with any answer

play01:24

p approximation p of the square

play01:28

root such that p square or

play01:31

equivalently p * p

play01:32

-x in absolute value is

play01:35

less than epsilon for some given

play01:38

tolerance parameter epsilon,

play01:39

such as epsilon equal 10 to the -6.

play01:45

The brute force iterative approach

play01:47

is to divide the interval between

play01:50

x and 1 into many many points,

play01:52

let's say 1,000,000 equally spaced points,

play01:56

and then traverse those points,

play01:58

loop over the points one by one to find the point

play02:03

p such that p * p is close enough to x.

play02:08

Now, the drawback of this

play02:10

approach is that it is very slow.

play02:13

It would take in the order

play02:15

of 1,000,000 steps.

play02:17

We know that square root of x is in

play02:20

the interval between x and 1.

play02:23

Instead of searching for square

play02:25

root of x iteratively,

play02:26

as in the previous example,

play02:28

the idea is to examine the middle element

play02:33

of the interval between

play02:35

x and 1 so this is mid .

play02:37

The average of x and 1 x + 1 over 2,

play02:42

and then compare the mid square

play02:45

with x. If case one, if we are lucky,

play02:53

if the absolute value of mid square

play02:55

-x is less than epsilon,

play02:57

where epsilon is our given tolerance

play02:59

parameter, we're done. mid is a

play03:02

desired approximation of the

play03:03

square root. Will stop.

play03:09

If mid square

play03:13

is less than x, or equivalently

play03:19

mid less than square root of x,

play03:21

then we know that

play03:25

square root of x is greater than

play03:27

mid and it is less than 1,

play03:29

so it must be in this sub interval.

play03:34

If

play03:38

in the remaining case, mid

play03:41

square is greater than x

play03:44

or equivalently, mid greater than square

play03:46

root of x and square root of x is less than mid.

play03:49

It is also greater than or equal to x,

play03:52

so it must be in this sub interval.

play03:56

So here if mid times mid less than x

play03:59

we narrow down the search to

play04:02

the interval between mid and 1.

play04:05

Else, we narrow down the search

play04:07

to the interval between x and mid.

play04:10

This is called the Bisection method

play04:14

becauses we're bisecting the search interval,

play04:17

and this is very efficient

play04:21

because at each, so at this iteration,

play04:23

at each iteration,

play04:26

we're dividing the search

play04:30

interval length by 2.

play04:33

We're going to keep on doing this

play04:37

until we get that mid squared

play04:40

-x absolute value is at most epsilon.

play04:44

Initially,

play04:45

the length of our search is at

play04:48

most 1. After the first iteration,

play04:50

its length would be at most half.

play04:53

After the second iteration,

play04:55

the length of the search interval

play04:57

would be at most 1 over 4.

play04:59

And so, after k iteration,

play05:01

the length of our search interval will

play05:03

be at most 1 over 2 to the k.

play05:09

Note that here it's easy to

play05:14

multiply mid by mid and

play05:17

a key point here is that by

play05:21

comparing mid times mid with x,

play05:24

we can actually tell whether

play05:26

mid square root of x is on

play05:28

this side or on that side.

play05:32

Translate this algorithm into a Python code.

play05:45

We need two variables low and high

play05:49

to keep track of our search interval

play05:54

low is initially X and high is initially one.

play05:58

We also need a third variable mid

play06:02

Initialized to the average of low and high

play06:04

(low+high)/2

play06:08

we have a loop.

play06:10

I will use a while loop and this is the.

play06:15

stopping condition so the loop conditon

play06:17

condition is going to be while

play06:20

absolute value of (mid*mid - x)

play06:22

is strictly greater than epsilon

play06:25

mid*mid - x

play06:29

strictly greater than optional.

play06:31

And in the body of the while,

play06:33

first we check this case.

play06:36

If mid times mid.

play06:41

Is less than X. In the general case,

play06:44

we need to narrow down the search interval

play06:47

to the interval between mid and high,

play06:50

which boils down to updating the low to mid.

play06:56

high remains the same and there is no point

play06:58

in saying high = high

play07:01

Else, which correspond to this case,

play07:04

and more specifically to the

play07:06

case when mid*mid

play07:08

is strictly greater than X.

play07:10

They cannot be equal because

play07:12

of the loop condition here.

play07:15

Else we update high, so high becomes

play07:20

mid. Mid and low remains the same

play07:23

What's missing is the update statement.

play07:27

We need to update mid

play07:29

After updating low and high

play07:31

without updating mid

play07:32

if we enter this loop

play07:35

we will get stuck in infinite loop.

play07:38

So here we update mid again

play07:41

mid = (low+high)/2

play07:46

And at the end, when we're done, we print

play07:54

mid as the approximate square root.

play07:59

This is the clean version of the code.

play08:02

Same code except here we initially read X.

play08:06

On the float, this is epsilon.

play08:10

We could also get epsilon from the user

play08:12

here we initialize low, high, and mid

play08:14

this is our loop and this is the if else statement

play08:16

and here we update mid

play08:18

and at the end we print the

play08:21

square root of X is mid,

play08:23

note that if initially we were lucky and

play08:27

mid*mid is close enough to x

play08:30

then we're not going to enter this

play08:32

loop and will immediately after

play08:34

setting the mid, will print the Mid

play08:37

as the approximate square root.

play08:39

Let's track it now in an example where

play08:42

X = 0.5 and epsilon 0.01.

play08:45

This is low initialized to x = 0.5

play08:47

high to one and this is

play08:51

mid and this is mid times mid

play08:53

not close enough to x with respect to epsilon

play08:56

to 0.01 and it is greater than X.

play08:59

So we narrowed down to the left subinterval

play09:02

we find mid again

play09:05

mid*mid is not close enough

play09:08

to X and it is less than X

play09:12

so we narrow down to the

play09:14

right subinterval

play09:16

Again mid times mid is not close

play09:19

enough to axe and it is less than X,

play09:22

so narrow down to the right subinterval.

play09:26

And here also mid*mid

play09:28

is not close enough

play09:31

and it is greater than X.

play09:34

So we narrowed down to the left subinterval

play09:38

here mid times mid

play09:42

Is close enough to X with respect to 0.01,

play09:46

so 0.01, so we stop.

play09:50

Now, when analyzed,

play09:51

the speed of the bisection method.

play09:54

As previously noted,

play09:55

the length of our search interval decreases

play09:57

exponentially with the number of iteration.

play09:59

In particular,

play10:00

before entering the loop,

play10:02

our search interval

play10:03

we start at X and the low is X,

play10:06

and the high is one

play10:08

the length is 1-x

play10:11

After first iteration we divide by two,

play10:13

so we get (1-x)/2

play10:16

After the second iteration

play10:17

we divide by two again.

play10:19

So we get (1-x)/(2^2)

play10:22

After K iterations we will get

play10:24

(1-x)/(2^k)

play10:26

Now we need to estimate the

play10:28

error, approximation error,

play10:29

which is the absolute value of

play10:32

mid - square root of x

play10:35

In general,

play10:36

this is our search interval

play10:41

low , High. This is mid.

play10:46

And this is square root of X.

play10:48

Somewhere in this interval.

play10:51

We need to estimate.

play10:54

This distance, in the worst case

play10:57

square root of X is here or here.

play11:00

So in the worst case,

play11:03

this error is at most the length

play11:06

of the interval over 2. So

play11:10

mid - square root of X absolute value

play11:14

is at most interval length/2

play11:18

which is (high-low)/2

play11:25

Therefore, Given that we know the

play11:28

search interval length from this column

play11:30

before entering the loop,

play11:32

the error is at most (1 - X)/2.

play11:35

This (1 - X)/2, which is at most half.

play11:40

Similarly, here there are is at most

play11:43

the length is (1-x)/2, so the error

play11:47

would be at most (1-x)/(2^2)

play11:50

which is at most (1/2^2) and so on.

play11:54

After second iteration we get (1/2^3)

play11:58

after K iteration get (1/2^(k+1))

play12:03

In summary, after K iteration,

play12:05

the approximation error is

play12:07

at most (1/2^(k+1))

play12:12

So for K equal, for example 10,

play12:15

after 10 iterations will get the error to.

play12:19

The error will be upper bounded

play12:22

by (1/2^11)

play12:26

Which is why

play12:27

which is why the bisection method

play12:29

is efficient.

play12:30

It can quickly decrease the error.

play12:34

A final remark is that Heron's method

play12:37

which we have seen in the first topic in

play12:39

this course has a faster convergence rate,

play12:42

but its convergence analysis is less

play12:44

trivial than that of the bisection method.

play12:47

In this lesson,

play12:48

we've seen the bisection method

play12:51

applied to the numerical problem

play12:53

of approximating the square root.

play12:55

The bisection method is also

play12:57

called binary search. Later in this

play12:59

course we will see binary search

play13:01

applied to discrete problems such as

play13:04

searching a sorted list of numbers.

Rate This

5.0 / 5 (0 votes)

الوسوم ذات الصلة
Bisection MethodSquare RootsNumerical AnalysisPython CodingAlgorithmsFloating PointAccuracyBinary SearchHeron's MethodEducational Content
هل تحتاج إلى تلخيص باللغة الإنجليزية؟