Mandelbrot set: Difference between revisions
Content added Content deleted
(→Normalized Counting, Distance Estimation, Mercator Maps and Deep Zoom: Added comments and final adjustments) |
(→Normalized Counting, Distance Estimation, Mercator Maps and Perturbation Theory: Only Float64x2 are fast, but you need at least Float64x3. Therefore, the MultiFloats example has been replaced and superfluous whitespace has been deleted.) |
||
Line 6,633: | Line 6,633: | ||
D = zeros(size(C)) |
D = zeros(size(C)) |
||
for i in 1:h+1 |
for i in 1:h+1, j in 1:d+1 |
||
⚫ | |||
for j in 1:d+1 |
|||
delta, index = C[i, j], 1 |
|||
for k in 1:n |
|||
⚫ | |||
for k in 1:n |
|||
z, dz = S[index + 1] + epsilon, 2 * z * dz + 1 |
|||
if abs2(z) > abs2(r) |
|||
⚫ | |||
break |
|||
end |
|||
index = index + 1 |
|||
if abs2(z) < abs2(epsilon) # rebasing when orbit is near zero |
|||
epsilon, index = z, 1 |
|||
epsilon, index = z, 1 |
|||
end |
|||
end |
end |
||
⚫ | |||
end |
end |
||
Z[i, j], dZ[i, j], E[i, j] = z, dz, epsilon |
|||
end |
end |
||
Line 6,656: | Line 6,654: | ||
heatmap(D' .^ 0.025, c=:nipy_spectral) |
heatmap(D' .^ 0.025, c=:nipy_spectral) |
||
savefig(" |
savefig("Mercator_Mandelbrot_rebase_map.png")</lang> |
||
The images can be verified by a (slow) calculation with BigFloats. There are libraries that are faster than BigFloats, for example DoubleFloats.jl and MultiFloats.jl. Unfortunately, the precision of the DoubleFloats is not sufficient, and only the double MultiFloats (Float64x2) are fast. For deep zoom images you need at least triple or quadruple MultiFloats (Float64x3, Float64x4), but they are slower than BigFloats. |
|||
The MultiFloats.jl library can be used to verify the results. To do this, however, the complex exponential function must be broken down into real cosine and sine functions and these functions must be calculated with BigFloats. However, the one-off calculation with a few BigFloats before and after the loop only has a small impact on the calculation speed. Since the number pi is missing from the library, 2*pi is replaced by acos(0)*4. Although the calculation with MultiFloats is much faster than with BigFloats, it is much slower compared to the perturbation calculation. |
|||
<lang julia>using Plots |
<lang julia>using Plots |
||
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
||
setprecision(BigFloat, 256) # set precision to 256 bits (default) |
|||
using MultiFloats |
|||
setrounding(BigFloat, RoundNearest) # set rounding mode (default) |
|||
MultiFloats.use_bigfloat_transcendentals() |
|||
d, h = 10, 200 # pixel density (= image width) and image height |
d, h = 10, 200 # pixel density (= image width) and image height |
||
n, r = 60000, 100000 # number of iterations and escape radius (r > 2) |
n, r = 60000, 100000 # number of iterations and escape radius (r > 2) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
A, B = collect(x), collect(y) |
A, B = collect(x .* pi), collect(y .* pi) |
||
C = (.- 4.0) .* |
C = (.- 4.0) .* exp.((A' .+ B .* im) .* im) .+ a .+ b .* im |
||
Z, dZ = zero(C), zero(C) |
Z, dZ = zero(C), zero(C) |
||
Line 6,691: | Line 6,689: | ||
heatmap(D' .^ 0.025, c=:nipy_spectral) |
heatmap(D' .^ 0.025, c=:nipy_spectral) |
||
savefig(" |
savefig("Mercator_Mandelbrot_bigfloat_map.png")</lang> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |