{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"using PyPlot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Julia Sets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Julia set is named after the French mathematician Gaston Julia. \n",
"For a complex number c, the filled-in Julia set of c is the set of all z for which the iteration z → z^2 + c does not diverge to infinity. The Julia set is the boundary of the filled-in Julia set. For almost all c, these sets are fractals.\n",
"(For more info e.g. see https://classes.yale.edu/fractals/MandelSet/welcome.html, https://en.wikipedia.org/wiki/Julia_set)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Complex Type\n",
"For representing complex number Julia provides a type Complex. For the imaginary part of a complex number, Julia uses the global constant im for representing the principal square root of -1. It was deemed harmful to use the name i for a global constant, since it is such a popular index variable name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Serial Julia set implementation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"# a simple julia set implementation\n",
"# this is very similar to a mandelbrot code, but we use a constant C everywhere\n",
"\n",
"function julia_set(q::Array{Complex64,2}, max_iter)\n",
" \n",
" C = -0.75-0.2*im\n",
" output = Array(Uint16,size(q)) # to store the result\n",
" \n",
" for i in 1: size(q,1), j in 1:size(q,2) # go over all entries of q\n",
" iter = 0\n",
" num = q[i,j]\n",
" \n",
" # compute the number of needed iterations for the current entry of q\n",
" while(norm(num)<4.0 && iter \n",
" for i in localindexes(q)\n",
" iter = 0\n",
" num = q[i]\n",
" while(norm(num)<4.0&&iter