Jackson Collins
Jackson Collins

Reputation: 120

Root Finding Algorithm of a Positive and Negative root

enter image description here

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

Answers (1)

Peter Cordes
Peter Cordes

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

Related Questions