Metallic ratios: Difference between revisions
Content added Content deleted
Line 345: | Line 345: | ||
printlucas(b, len=15) = (for i in take(Lucas(b), len) print(i, ", ") end; println("...")) |
printlucas(b, len=15) = (for i in take(Lucas(b), len) print(i, ", ") end; println("...")) |
||
function lucasratios(b, len) |
|||
iter = BigFloat.(collect(take(Lucas(b), len + 1))) |
|||
return map(i -> iter[i + 1] / iter[i], 1:length(iter)-1) |
|||
end |
|||
function metallic(b, dplaces=32) |
function metallic(b, dplaces=32) |
||
setprecision(dplaces * 5) |
setprecision(dplaces * 5) |
||
ratios, err = lucasratios(b, dplaces * 50), BigFloat(10)^(-dplaces) |
|||
errors = map(i -> abs(ratios[i + 1] - ratios[i]), 1:length(ratios)-1) |
|||
next = iterate(iter); (_, state) = next; next = iterate(iter, state) # iterate past first 1 in sequence |
|||
iternum = findfirst(x -> x < err, errors) |
|||
for iterations in 1:dplaces*100 |
|||
⚫ | |||
(x2, state) = next |
|||
format(ratios[iternum + 1], precision=dplaces), |
|||
newestimate = BigFloat(x2) / BigFloat(x1) |
|||
⚫ | |||
if abs(newestimate - estimate) < err |
|||
⚫ | |||
format(newestimate, precision=dplaces), |
|||
⚫ | |||
break |
|||
end |
|||
x1, estimate, next = x2, newestimate, iterate(iter, state) |
|||
end |
|||
end |
end |
||