Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How can I make my own fractals?

  1. Jan 1, 2013 #1
    Hello everyone. You probably all know about the Mandelbrot set. I am not here to ask questions about the set itself, but how I can graph fractals similar to it. Is there a program where I can input my own equations? Or would I have to be a java expert to do so? The fractals that I want to make are similar to the Mandelbrot set: I want the computer to color a point black if the point converges after a number of iterations and I want to color the points that do not converge according to escape time.

    By the way, I don't know the first thing about programming/computer science.
     
  2. jcsd
  3. Jan 2, 2013 #2

    Borek

    User Avatar

    Staff: Mentor

  4. Jan 2, 2013 #3

    jim mcnamara

    User Avatar

    Staff: Mentor

    Great link, that one. Thanks Borek.
     
  5. Jan 2, 2013 #4
    Would you recommend any of these in particular for a mac? I downloaded a few and most of them only allow you to examine preset functions. Do any of them allow you to input your own functions?

    Also, I am worried that even if I find a decent fractal generator, it may not be able to do what I want. I am interested in generating a fractal where, in the style of the mandelbrot set, a point z is colored black if it converges for ##z^z^z...## and it is colored based on escape time if it diverges.
     
    Last edited: Jan 2, 2013
  6. Jan 2, 2013 #5

    Borek

    User Avatar

    Staff: Mentor

    Sorry, can't help you further.
     
  7. Jan 3, 2013 #6
    I don't understand anything about fractals, so be careful with this.

    This is a few lines written in Mathematica which I think tries to do what you are asking for. It creates a square matrix of z^z^z... as long as the z^z^z are within a distance of 2 from the origin. Some wiki page said that was the criteria for escaping to infinity. It only builds a tower of z^z^z... 20 levels high before it bails out and assumes it will never escape. Then it displays a plot of that table. It does this over -2<=a<=2, -2<=b<=2 with steps of .01 for a and b. Norm[] is a function that calculates the distance from the origin to a point.

    In[1]:= ArrayPlot[
    Table[n = 0; z = a + I*b; r = z;While[Norm[r] < 2. && n < 20, r = r^z; n++]; n,{a, -2., 2., .01}, {b, -2., 2., .01}]
    ]

    Out[1]= <plot snipped and attached>

    I assumed your equation wouldn't be fractal because it seemed too simple to me. The first half dozen times I tried this I got a round black disk and thought I was right. Then I changed something to try to make this more readable and got a black sheet. That seemed wrong and I changed all kinds of things before I got the attached image. This may still be wrong, but you need someone who knows a lot more than I do to tell if this is right or not.

    If I have errors in this and someone can explain how I am supposed to fix it then I would try to do that.

    Mathematica is not free. For some it isn't even cheap. But it does run on Mac. If you ask very very nicely you can get a free trial version that works for a couple of weeks or a month. If you arranged to have nothing else to do and didn't sleep and you saw how to ask questions about Mathematica so you quickly got good answers then you might be able to learn a lot and get a lot of fractal images from various equations done before your trial expired. I would suggest getting an introductory book on Mathematica and learning as much as you can before you ask for your trial so that you don't spend your limited trial time frustrated with little problems instead of getting good pictures done. I don't think the trial lets you save files, so you may be limited to capturing the images on the screen.

    If you want a few more images of this changing the location, the resolution, the maximum number of steps or zooming in on part of this then I would offer to do a few more experiments to help you get ready to start doing this yourself.

    If after your trial you decide Mathematica is the tool for you then there are somewhat reasonably priced versions for home use. Add the price of a couple of books that will help you learn how to use it and you can try to learn to do fractals and lots of other things.

    One other caution. As you see, Mathematica can be very flexible and you can change the function you use as well as anything else, but such flexibility sometimes comes at the price of speed. The simple example I showed will be substantially slower than a carefully optimized program written by an expert. It is sometimes possible to speed up Mathematica calculations, but that often requires more knowledge than a beginner can easily find.
     

    Attached Files:

    Last edited: Jan 3, 2013
  8. Jan 3, 2013 #7
    Thanks a lot! That thing looks really cool! What did you change about the equation?
     
  9. Jan 3, 2013 #8
    I tried to use what I thought your equation was, that was to check z, z^z, z^z^z, z^z^z^z,... until that was either a distance of 2 or more away from the origin or until it had a stack of 20 exponents and I bailed out.

    The fumbling around was trying to make the example as simple and understandable as I possibly could, so you or others could hopefully understand it and point out any mistakes.

    If you are fairly sure what the equation should be then you might be able to calculate the result for some particular value of z. If you let me know what the values for z and powers of z are then I could see if I'm getting the same result you are. That might help expose mistakes.
     
  10. Jan 4, 2013 #9
    I have a program that generates the Mandelbrot Set on my http://schnitzld.appspot.com/projects/1 [Broken]. It's written in JavaScript and uses the new HTML 5 canvas tag. The source is cobbled together from a couple of other programs that I have referenced, and I have grand plans for it that include a much better color palette and much deeper zoom. You can view the source.

    I'm posting it because the program is actually very simple, and the platform (JavaScript/HTML5) is available to most anyone with a computer, without downloading any extra software. All of the meaningful code is inside the drawMandelbrot() function and all it does is set some initial parameters and then with a system of three loops, iterates over every x,y coordinate on the canvas (that's two loops, for all x, for all y) and then runs an inner loop (for i until max_iterations) to determine whether the complex number that defines that x,y coordinate (i.e 1 + 2i is x,y coord 1,2) is part of the set or not. The maths is very easy, and the program is too.

    As for generating other fractals, I have a program called ChaosPro but to be honest, I haven't used it much, or recently. I believe you can load new formulas as files and use it to generate your own, but you would have to investigate that yourself.
     
    Last edited by a moderator: May 6, 2017
  11. Jan 4, 2013 #10
    You've got the idea, that's exactly what I want to do. How long did that take your computer to render? By the way, I was not even sure if it would be a fractal. I had no knowledge going into this what it might look like.

    Edit: My math teacher suggested that I find a way to do this by iterations. I'll spare you the ugly work, but here is the value of ##(a+bi^{(c+di)}##:
    $$(a+bi^{(c+di)}=(a^2+b^2)^{c/2}e^{-d*\text{arctan}(b/a)}\text{cis}(d*\text{ln}(a^2+b^2)/2)\text{cis}(c*\text{arctan}(b/a))$$

    Thus, the iteration is:

    $$a+bi \to (a+bi^{(c+di)}=(a^2+b^2)^{c/2}e^{-d*\text{arctan}(b/a)}\text{cis}(d*\text{ln}(a^2+b^2)/2)\text{cis}(c*\text{arctan}(b/a))$$

    c+di is the complex number whose convergence we are testing. a+bi is the number that is obtained from an iteration. Thus, for the initial iteration, a+bi=c+di.
     
    Last edited: Jan 4, 2013
  12. Jan 4, 2013 #11
    For the simple example I showed: about 35 seconds.
    Cut the step size in half, so 4x the points, and raise exponents to 40: about 5 minutes 40 seconds.

    I'm not sure whether doing the repeated multiplies would be slower than doing the arctan and cis and log or not.
     
  13. Jan 4, 2013 #12
    Can I see the higher quality version?
     
  14. Jan 4, 2013 #13
    Doesn't look much different to me
     

    Attached Files:

  15. Jan 4, 2013 #14
    This is great. It appears, at the bottom left and right of the set, that points outside the radius of 2 converge. Could you make try making the set bounded by a circle of radius 3?
     
    Last edited: Jan 4, 2013
  16. Jan 4, 2013 #15
    I still have no idea whether this is correct or not.
    I'm guessing the wiki "diverges for x>2" may only apply for repeated squaring and not for your exponentiating

    In[1]:= ArrayPlot[
    Table[n=0;z=a+I*b;r=z;While[Norm[r]<3.&&n<20,r=r^z;n++];n,{a,-3.,3.,.01},{b,-3.,3.,.01}]
    ]

    Out[1]= plotSnipped

    In[2]:= Export["zfrac3.jpg",%,ImageResolution->200]

    Out[2]= zfrac3.jpg
     

    Attached Files:

  17. Jan 4, 2013 #16
    Do you know what it means if an area is grayer than another area? Is that based on escape time?
     
  18. Jan 4, 2013 #17
    The darker it is the more z's in z^z^z^z... were needed before the value of that became greater than 2 (or 3).

    So out side the circle of radius 2 (or 3) is white because it took zero exponents to be greater than 2 (or 3), in other words z was already enough.

    The slightly darker shade just inside the circle took one exponent, z^z to escape. The next darker shade in the "bands" on the "wings" took two exponents, z^z^z to escape.

    The black center did not escape in 20 (or 40) exponents.
     
  19. Jan 6, 2013 #18
    around the one and a half second mark in Mathcad 15 on a Dell Dimension 521 (Athlon 54 dual-core 2.5 GHz with 4GiB RAM running Windows 7 32-bit) - the lighter the image, the quicker the escape. Around one second for an n=64 standard Mandelbrot over the same x and y ranges.

    attachment.php?attachmentid=54495&stc=1&d=1357517664.jpg
     

    Attached Files:

  20. Jan 6, 2013 #19
    That's interesting that yours rendered much more quickly than Bill's... Do you think that it is because your program is faster?

    I'm considering investing in a math program solely for creating original fractals like this one (although good graphing abilities and other features wouldn't hurt). Should I get the Mathematica student edition? Any other recommendations?

    Thanks
     
  21. Jan 7, 2013 #20
    Depends what you mean by 'program'. I'm using Mathcad, a completely different application. I think the Mathcad program I showed is equivalent to the Mathematica one which implies that Mathcad is faster, but it may be that the Mathematica Table function is slower than an equivalent Mathematica For program.

    If you're going to solely create fractals, then I'd recommend a specialized fractal application. If you want a generalized application then it would be helpful to know what else you would want to do. Mathematica SE seems like a very good choice. However, I use Mathcad because it's a good general purpose mathematical application that allows the user to use near-standard maths notation to write equations and display/graph results on the same 'piece of paper'. The image I posted is exactly as the Mathcad worksheet looks, including the fractal plot (*).

    Have a look at http://www.ptc.com/product/mathcad/ - you can download an evaluation copy and the user forum http://communities.ptc.com/community/mathcad is a pretty good place to ask for advice.

    -------------------

    (*) The gray dotted line that goes across the plot is where the page boundary would be if I'd printed the worksheet as is - I'd move stuff around to avoid this if I was actually going to print it. The image below shows a variant of the program in which I'd shuffled the 'regions' further up the page. It also illustrates another feature of Mathcad, that is the ability to write programs across the page as well as down the page. Mathcad evaluates left-to-right then top-to-bottom. Consequently, the second function f supersedes the first definition resulting in a Mandelbrot like figure (note the power of z is 2.1 rather than 2, hence the bident rather than the single prong along the negative x-axis).

    attachment.php?attachmentid=54506&stc=1&d=1357548127.jpg
     

    Attached Files:

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook