Skip to content

Instantly share code, notes, and snippets.

@johnmyleswhite
Created April 2, 2020 14:59
Show Gist options
  • Save johnmyleswhite/39f42e57618ee83b10c51499d94bc461 to your computer and use it in GitHub Desktop.
Save johnmyleswhite/39f42e57618ee83b10c51499d94bc461 to your computer and use it in GitHub Desktop.
function fixed_point(f, x0)
x, x_old = f(x0), x0
n = 1
while x !== x_old
x, x_old = f(x), x
n += 1
end
(x, n)
end
fixed_point(x -> 0.1 * x, 1.0)
fixed_point(x -> 10.0 * x, 1.0)
fixed_point(x -> exp(x), 1.0)
fixed_point(x -> x + 1.0, 1.0e16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment