Anonymous user
Roots of a function: Difference between revisions
→{{header|Julia}}
Line 1,265:
<pre>[0.0,1.0,2.0]</pre>
Without the Roots package, newton's method may be defined in this manner:
<lang Julia>
function newton(f, fp, x,tol=1e-14,maxsteps=100)
xnew, xold = x, Inf
fn, fo = f(xnew), Inf
counter = 1
while (counter < maxsteps) && (abs(xnew - xold) > tol) && ( abs(fn - fo) > tol )
x = xnew - f(xnew)/fp(xnew) # update step
xnew, xold = x, xnew
fn, fo = f(xnew), fn
counter = counter + 1
end
if counter == maxsteps
error("Did not converge in ", string(maxsteps), " steps")
else
xnew, counter
end
end
</lang>
=={{header|Liberty BASIC}}==
|