Question: In this task, a simple implementation of the bisection method for finding roots of continuous functions is to be developed. Let f: [ a ,

In this task, a simple implementation of the bisection method for finding roots of continuous functions is to be developed. Let f: [a, b], Real numbers be a continuous function with a < b and f(a)*f(b)<0. According to the intermediate value theorem, f has at least one root in [a, b].
The bisection method works as follows:
1. Set L = a, R = b.
2. If the condition f(L)* f(R)<=0 is not met, terminate. Otherwise:
. Test whether R - L < TOL, where TOL is user tolerance (e.g., TOL =10^-7). If yes, there is a root in [L, R]; otherwise,
. Continue with subintervals [L,(L+R)/2] and [(L+R)/2, R] following step 2.
Write a recursive function
`void bisect(double L, double R, double TOL)`
implementing the bisection method, and a double function `f(double x)` returning f(x).
Test your implementation with various functions and intervals, outputting the intervals containing roots and the function values at the midpoint.
For instance, running with f(x)= x^3-4x^2+6x -25 and L =0, R =7 might produce output like:
```
"A root of f lies in [4.044723e+00,4.044723e+00] f((L+R)/2)-2.074738e-08."
```
For f(x)= sin(x), you might get output similar to:
```
"A root of f lies in [0.000000e+00,5.215406e-08] f((L+R)/2)-2.607703e-08"
"A root of f lies in [3.141593e+00,3.141593e+00] f((L+R)/2)=-1.741103e-09"
"A root of f lies in [6.283185e+00,6.283185e+00] f((L+R)/2)--2.259483e-08."
```

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!