Created
July 24, 2012 16:08
-
-
Save StefanKarpinski/3170899 to your computer and use it in GitHub Desktop.
This file contains 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
julia> quality(x,a::Rational) = log(den(a),1/abs(x-a)) | |
julia> function maxquality(x,n) | |
Q = -Inf | |
for k = 1:n | |
a = rational(x,1/2^k) | |
if a == x break end | |
q = quality(x,a) | |
if isfinite(q) && Q < q | |
Q = q | |
end | |
end | |
return Q | |
end | |
julia> maxquality(pi,10) | |
3.429288337281781 | |
julia> median(map(x->maxquality(x,10),rand(100000))) | |
3.189712422680679 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment