Ok so i have a function which I need to find the root closest to x=100.
The function is f(x)=x-tan(x)
So far I cannot figure out how to localize the program around x=100
this is my code thus far (note i had to change tan(x) to arctan because my program couldn't take it for some reason)
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
Sorry, I'm not sure why my numbers aren't showing, but i keep getting the number .016 as my root, which is right. But it is only the first root, I need the root closest to 100
I can imagine there could be two problems with this case.
One, the evaluating the function or its derivative may give a result which is infinite, in which case, the program may give a NaN (not a number) error.
Secondly, if the starting point is not very close to the root, the next approximation may be further away, rather than closer.
Try plotting a graph of 1-tan(x) around the range x=101 to 103, and you will see how the slope varies dramatically.
Use the graph to help select a better starting point. I tried 102.0 and the program failed. But with 102.1 it was successful.