# Finds multiple roots of a function.
# function to find zero of
function f(x) begin
# derivative of function to find zero of
function df(x) begin
# value we are solving for is 0
fval = fill(0., 10, 1)
# start Newton's method at 1, 2, .., 10
xini = real(seq(10))
# maximum number of iterations
mitr = 10
xsolve = snewton(function f, function df, fval, xini, mitr)
# put solutions in order
xsolve = sort(xsolve)
print "The roots of sin(x) between 1 and 10 are"
for i = 1 to rowdim(xsolve) begin
ok = 1. <= xsolve(i) and xsolve(i) <= 10.
if i <> 1 then ok = ok and |xsolve(i) - xsolve(i-1)| > 1e-4
if ok then print xsolve(i)
The roots of sin(x) between 1 and 10 are