Question
The equation f(x) = (1 x) cos x sin x = 0 has at least one root between a = 0 and b = 1
The equation f(x) = (1 x) cos x sin x = 0 has at least one root between a = 0 and b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows: a. It finds the midpoint r = (a + b)/2. b. If f(r) = 0, then r is the root. If |b a| is very small less than then also we can take r as the root. In either of the cases, our job is done. c. If f(r) 0 and f(a)f(r) < 0, then the root lies between a and r. We assign r to b and go to step a. d. If f(r) 0 and f(b)f(r) < 0, then the root lies between r and b. We assign r to a and go to step a. e. If the number of iterations is high, we may stop the process with appropriate message. Write the following functions with the specifications mentioned. 1. Function func takes a real number x as argument and returns the value of f(x). 2. Function cbracket takes two real numbers a and b as arguments and returns 1 if at least one real root of f(x) lies between a and b, and 0 otherwise. 3. Function rootb that takes three real numbers a, b, and an integer Nmax as arguments. This function returns the root of f(x) using bisection method. If the number of iterations is more than Nmax then the function terminates with appropriate message. Write a C program using the above functions. This program accepts a; b and Nmax from the user and prints out the root (if any).
Sample output:
Enter eps and Nmax :1.e6 20
Enter a, b :0 3
Root must be bracketed
Enter eps and Nmax :1.e6 10
Enter a, b :0 2
Increase the max iteration
Enter eps and Nmax :1.e6 50
Enter a, b :0 2
Root = 0.479731
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started