Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

Understand the nature and importance of collective bargaining

Answered: 1 week ago