Metallic ratios: Difference between revisions

m
Line 345:
 
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)
setprecision(dplaces * 5)
estimateratios, err, x1= lucasratios(b, iterdplaces =* big"0.0"50), BigFloat(10)^(-dplaces), big"1", Lucas(b)
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
println("After $iterations(iternum + 1) iterations, the value of ",
(x2, state) = next
format(ratios[iternum + 1], precision=dplaces),
newestimate = BigFloat(x2) / BigFloat(x1)
" is stable to $dplaces decimal places.\n")
if abs(newestimate - estimate) < err
println("After $iterations iterations, the value of ",
format(newestimate, precision=dplaces),
" is stable to $dplaces decimal places.\n")
break
end
x1, estimate, next = x2, newestimate, iterate(iter, state)
end
end
 
4,106

edits