Finding roots of an equation {resolved}
I need to write an algorithm that can find the roots of any equation (of the form y=f(x).
It would have to do it by testing X values at certain points and homing in on the root by finding the sign change. What is the most efficient method of doing this?
Re: Finding roots of an equation
Are you considering equations with complex roots too?
e.g.
(x^2) = -2
"Any" equation is quite broad.
Re: Finding roots of an equation
Not complex ones no. Only Y=0 (for now)
OK, not ANY curve then :rolleyes: :thumb:
I'm not doing this by re-arranging equations or any cheating like that, just by calculating the Y at certain X values and interpolating to find roots.
Function Get_Y_Value(x) 'can be treated as a "black box", we don't need to know the equation itself.
Re: Finding roots of an equation
So you'll need some sort of heuristic method to produce a reasonable guess at a root, then decrease or increase x depending on whether you're too high or low.
You can scale the increase or decrease amount according to how far from y=0 you are, i.e. decrease the change as you approach y=0.
As for the initial guess, hmm..I don't know really. It probably doesn't matter if your guess is a long way off anyway as long as you use the change-scaling approach..
Also are you going to allow equations with no roots and detect that?
Re: Finding roots of an equation
Its OK. I have sorted it out now. Cheers. :thumb: