Hey vercammen.
Are you trying to find the root to f(x) = tan(x) = 0 with the bisection method?
What will happen if the bisection method is used with the function f(x) = tan(x) and
a) [3,4]
b) [1,3]
Attempt:
Check the signs of the function:
f(x) = tan(x)
a) f(3)*f(4) = -0.165 <0 => the root is between 3 and
b) f(1)*f(3)= -0.222<0 => the root is between 1 and 3 ,
but this is obviously wrong.
Please, help.
Remember, the bisection root finding method works for continuous functions on the interval. So the bisection method applied to tan(x) on [3,4] does fine. But tan(x) has an infinite discontinuity on [1,3] at x=pi/2. So there's no reason to suppose bisection will work; in fact tan(x) is never 0 on [1,3].
If you apply the bisection method and get the sequence {xn}, then xn approaches pi/2 as n approaches infinity. I really don't want to give an analytic proof of this, but if you try it by hand, you'll see what is happening. Alternatively, write a little program to compute say the first 1000 terms to see what you get:
#include <stdio.h>
#include <math.h>
double bisect(double (*f)(double),double x0, double x1, int n);
int main(void) {
double x0=1,x1=3,result;
result=bisect(tan,x0,x1,1000);
printf("After 1000 iterations, xn = %g with tan(xn) = %g\n",result,tan(result));
return(0);
}
/* bare bones bisection method; not really a workable version since no
tolerance is supplied, just do the method n times.
*/
double bisect(double (*f)(double x), double x0, double x1, int n) {
double m;
int i;
for (i=1;i<=n;i++) {
m=(x0+x1)/2;
if ((*f)(m)*(*f)(x0)<0) {
x1=m;
}
else {
x0=m;
}
}
return(m);
}
The above program produces result 1.5708 (approximately pi/2) with
tan(result)=1.63e+016, as expected a large value in magnitude.