Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Folder full of pertinent coursework

1666 views
Kernel: Python 2 (SageMath)

Julia Sets

Sean Paradiso

import math class JuliaSet(object): def __init__(self, c, n = 100): self.c = c self.n = n self._d = 0.001 self._complexplane = [] self.set = [] def juliamap(self, z): return (z ** 2) + self.c def iterate(self, z): m = 0 while True: z = self.juliamap(z) m += 1 if abs(z) > 2: return m if m >= self.n: return 0 def makeplane(self): plane = [i * self._d for i in range(int(-2 / self._d), int(2 / self._d), 1)] self._complexplane=[complex(x,y) for x in plane for y in plane] def set_spacing(self, d): self._d = d self.makeplane() def generate(self): self.set = [self.iterate(i) for i in self._complexplane] return self.set
object1 = JuliaSet(1+1j,)
object1.juliamap(1-1j)
(1-1j)
object1.iterate(1+1j)
1
object1.generate()
[]
I believe the simplest way to check whether the code is producing the correct output is to solve simple examples by hand and making sure the code produces a matching answer.
Another method may be to feed as input the same example into two codes that are believed to be working properly and making sure both answers correspond.
Based on the algorithm with which we are working, simple output can be achieved through easy to understand parameters such as the examples above:
- The complex number 1 ± 1i (or 1 ± 1j in our case)
As mentioned before, we can check these test cases by running them through the code and solving them by hand and making sure the results match