116k views
5 votes
Write a code to ompute an approximation to p by the following methods. Take 10 steps in each case. Print the answers to 15 digits. - (5 points) bisection method, starting interval [a,b]=[1,2].

User Khoxsey
by
8.0k points

1 Answer

4 votes

Final answer:

The question requires computing an approximation of pi using the bisection method over 10 steps. The process involves bisecting the interval [1,2], computing values of a function with a root at pi, and refining intervals until reaching an approximation with the desired accuracy.

Step-by-step explanation:

The question involves using the bisection method to approximate the value of "p." Since "p" is not defined in the context of the question, I will assume the student is referring to approximating the mathematical constant pi (π). The bisection method is a root-finding algorithm that repeatedly bisects an interval and selects a subinterval in which a root must lie for further processing. It is used to find a zero of the function in a specified interval. In this case, you might have a function f(x) that crosses zero at π, such as f(x) = sin(x). Here is a pseudo-code for approximating pi using the bisection method for the function f(x) = sin(x - π/2) = 0, which has a root at x = π/2 (which we can double to approximate pi).

  1. Let a = 1, b = 2, and error tolerance be sufficiently small (up to 15 digits of precision).
  2. Compute f(a) and f(b).
  3. Find the midpoint, c = (a + b)/2. Compute f(c).
  4. If f(c) is close enough to zero (within the error tolerance), stop and output c as the approximation of π.
  5. If not, determine the half-interval on which f changes sign (f(a)f(c) < 0 or f(b)f(c) < 0).
  6. Replace the end of the interval (a or b) with c and go back to step 3.
  7. Repeat the process until the approximation is within the desired tolerance,

Repeat for 10 steps to ensure the approximation of π to 15 decimal places. Remember that the actual function you apply the bisection method to should have a root at π, and the above example is based on f(x) = sin(x - π/2).

User Dustinmoris
by
7.3k points