This Gist was automatically created by Carbide, a free online programming environment.
Created
August 31, 2016 02:11
-
-
Save bijection/757b5c162c625a94de6525e50595e5f9 to your computer and use it in GitHub Desktop.
phase change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f(x){ | |
return x > 3.5938 | |
} | |
function find_phase_change(f, known_true, known_false){ | |
while(Math.abs(known_true - known_false) > 1e-3){ | |
var mid = (known_true + known_false) / 2 | |
f(mid) ? known_true = mid : known_false = mid | |
} | |
return (known_true + known_false) / 2 | |
} | |
find_phase_change(f, 10, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment