Created
February 25, 2022 01:40
-
-
Save XerxesZorgon/5205facbb7c7ef02999e27ead70a5d59 to your computer and use it in GitHub Desktop.
Plots trajectories and filled Julia sets
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
#= | |
Plot Julia functions | |
Load with: include("JuliaSetPlots.jl") | |
Written by: John Peach 13-Feb-2022 | |
Wild Peaches | |
Julia sets are defined as | |
z_{n+1} = zₙ² + c | |
where zₙ ∈ ℂ and c = x₀ + iy₀ | |
Mandelbrot sets are similar, but z₀ is fixed, and c ∈ ℂ. | |
=# | |
# Required packages | |
using Plots, LinearAlgebra | |
gr() | |
""" | |
plotIterates | |
Plots iteratations of the Julia function from in initial point z₀ ∈ ℂ and parameter c | |
Parameters | |
z₀: Starting point | |
c: Control parameter | |
n: Number of iteratations | |
Returns | |
Plot of n iteratations | |
""" | |
function plotIterates(z₀,c,n) | |
# Initialize trajectory | |
zₙ = length(z₀) | |
traj = zeros(ComplexF64,n,zₙ) | |
traj[1,:] .= z₀ | |
# Generate trajectory | |
for k = 1:zₙ | |
for j = 2:n | |
traj[j,k] = traj[j-1,k]^2 + c | |
end | |
end | |
# Plot trajectory. The display function is needed inside a function. | |
crvLabel = Array{String}(undef,zₙ) | |
for k = 1:zₙ | |
crvLabel[k] = string("z₀ = ", z₀[k]) | |
end | |
# Note permation of label string. | |
# Ref: https://discourse.julialang.org/t/transpose-of-an-array-of-strings/40431/8 | |
crvPlot = plot(traj, | |
linewidth = 3, | |
aspect_ratio = 1, | |
xlabel = "Real axis", | |
ylabel = "Imag axis", | |
title = "Julia Iterates", | |
arrow = :arrow) | |
#label = permutedims(crvLabel) | |
#legend = :outertopright) | |
display(crvPlot) | |
# Return trajectory | |
return traj | |
end | |
""" | |
plotJulia | |
Plots points in a Julia set | |
Parameters | |
c: Constant added to each iterate | |
""" | |
function plotJulia(c,xRng = [-1.6,1.6], yRng = [-1.6, 1.6]) | |
# Array of iteration counts | |
nx = 1281 | |
ny = 1281 | |
iterCounts = zeros(nx,ny) | |
# Locations | |
xLocs = range(minimum(xRng),stop = maximum(xRng),length = nx) | |
yLocs = range(minimum(yRng),stop = maximum(yRng),length = ny) | |
# Loop over x,y locations iterating until maxIter reached, or |z|² > 4 | |
maxIters = 1000 | |
for j = 1:nx | |
for k = 1:ny | |
z = xLocs[j] + yLocs[k]im | |
while iterCounts[j,k] < maxIters && norm(z) < 2 | |
z = z^2 + c | |
iterCounts[j,k] += 1 | |
end | |
end | |
end | |
# Display Julia set as a heatmap | |
display(heatmap(iterCounts')) | |
# Return array of iterations | |
return iterCounts | |
end |
Hi Glanz,
That's great you're getting a Masters in Mathematical Engineering, and
I'm sure you'll do just fine. I guess Pluto is probably slow because it's
reactive, but I like that feature for notebooks where the calculations are
relatively simple and speed isn't a problem. I used Pluto for the two most
recent posts, "Easy Chaos with Pluto"
<https://wildpeaches.xyz/blog/easy-chaos-with-pluto/> and "Tools of Chaos"
<https://wildpeaches.xyz/blog/tools-of-chaos/>. I'm planning a few more
like these, but have been asked by the Durham Medical Orchestra
<http://dmomusic.org/> to build a model of their practice room to see what
they might be able to do to reduce the chance that someone gets infected
with Covid. They're all fully vaccinated, but in many cases people don't
realize they've become infected until after an event. So, the chaos will be
delayed for a while.
Someone else extended one of the charts in "The Growing Gap":
[image: image.png]
which is probably a bit pessimistic, but I think people will be shocked at
how fast the fossil fuel crisis hits. I'm really worried about Europe, so I
hope you are OK. Meanwhile, if you come up with a cool idea for a blog
post, let me know and we'll get it into Wild Peaches!
John
…On Thu, Oct 13, 2022 at 11:32 AM Glanz ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi John,
I read your posts the "The Growing Gap" and "Mathics and Nebo", great
articles.. I believe that we will still depend on oil and gas till very
long, no matter if we try to convert to renewable energy, all still needs
fossil fuels. Politics, can be counted on why we still depend on oil and
gas.
I am studying master degree "Mathematical Engineering" now in Erasmus
Mundus program, in italy. It is very tight schedule, I hope I can manage to
learn them all and pass the exams.
About Pluto, why is it slow? Why the creator name it the slowest moving
planet? Even if it is not included as planet anymore currently, but next
time we learn from this case that we shall name something with similar
analogous meaning, name is a prayer I believe.
You are an amazing person, not only smart, but want to share your
knowledge in your blog for free, I wish one day I have the chance to write
article suitable for your blog and then I will show it to you, probably it
can be published on your blog.
I have this imagination that your articles can be printed on leaflet like
Rosary' paper that can be folded and back and forth it could contain 2
articles. Your articles is a science based that can be useful for the
Economies, people will be more knowledgeable, I am from a poor country thus
I know the most effective way to make a country to be rich is by the right
education with morale value.
An example is if more people read your blog/articles there will be less
uneducated people and therefore better country, less inequality, people be
more productive and smarter.
About human kind, I feel pessimist today, I am in Europe now, and I still
see a lot of negative impacts of overpopulation, throwing trashes randomly,
even in London too. Are electric cars and rockets really going to be
breakthroughs or only to showing Pride of some clans/nations. After
trashing the earth therefore trashing Mars and Space?
Working at MIT is a great opportunity, I believe you worked hardly before
and very intellectual that is why you are there right now, luck is when
preparation meets opportunity. All the best.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/5205facbb7c7ef02999e27ead70a5d59#gistcomment-4334250>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC3KQPN2DSUXH2HDYHWPXN3WDATR7ANCNFSM55EXAM3A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi John,
I read your posts the "The Growing Gap" and "Mathics and Nebo", great articles.. I believe that we will still depend on oil and gas till very long, no matter if we try to convert to renewable energy, all still needs fossil fuels. Politics, can be counted on why we still depend on oil and gas.
I am studying master degree "Mathematical Engineering" now in Erasmus Mundus program, in italy. It is very tight schedule, I hope I can manage to learn them all and pass the exams.
About Pluto, why is it slow? Why the creator name it the slowest moving planet? Even if it is not included as planet anymore currently, but next time we learn from this case that we shall name something with similar analogous meaning, name is a prayer I believe.
You are an amazing person, not only smart, but want to share your knowledge in your blog for free, I wish one day I have the chance to write article suitable for your blog and then I will show it to you, probably it can be published on your blog.
I have this imagination that your articles can be printed on leaflet like Rosary' paper that can be folded and back and forth it could contain 2 articles. Your articles is a science based that can be useful for the Economies, people will be more knowledgeable, I am from a poor country thus I know the most effective way to make a country to be rich is by the right education with morale value.
An example is if more people read your blog/articles there will be less uneducated people and therefore better country, less inequality, people be more productive and smarter.
About human kind, I feel pessimist today, I am in Europe now, and I still see a lot of negative impacts of overpopulation, throwing trashes randomly, even in London too. Are electric cars and rockets really going to be breakthroughs or only to showing Pride of some clans/nations. After trashing the earth therefore trashing Mars and Space?
Working at MIT is a great opportunity, I believe you worked hardly before and very intellectual that is why you are there right now, luck is when preparation meets opportunity. All the best.