Numerically+finding+roots+of+a+function+in+a+range

Numerically finding roots of a function in a given range
code format="vbnet" '  Approximately (numerically) finds and outputs all the roots of a given function f(x), '  within a given range of x values. '  It detects roots by changing function sign, so if function just touches X axis, it will not register such root. '  If it reports a root at x, that means abs(root-x)<eps. '  Just remember that we have no more then 16 significant digits in Double number, '      so setting very small eps is pointless (it will just hang).

'  x range xMin =-1 xMax = 3 '  If it reports a root at x, that means abs(root-x) there is a root, should drill deeper if dx < eps then   'we are close enough print " Just crossed axis, solution f( x) ="; y; " at x =";x LastY = y               dx = bigH   'after closing on root, continue with big step else x = x-dx 'step back dx = dx/10 'repeat with smaller step end if       end if    loop while x<xMax

print print " Finished checking in range specified."

end

'this is a function to find roots of. function f( x)       f = x^3 - 3*x^2 + 2*x end function code