Reputation: 120
Hi, I have to devise an algorithm for this. I've looked into bisection, newton and it seems like bisection method is correct but it requires a algorithm to go off. e.g. x^3 + x - 2 = 0. Is there anyway to have a generalised algorithm for this question?
Upvotes: 0
Views: 280
Reputation: 364240
Binary search will find (one of the) roots.
What they're suggesting is assuming the function is linear between (a, f(a))
and (b, f(b))
, and picking the point where a straight line between those points crosses the x axis. i.e. assume
f(x) = m * x + b
This will probably converge faster than simple binary search of new_x = (a+b)/2
.
Upvotes: 1