New in Wolfram
Mathematica
8: Compiler Performance Enhancements
◄
previous

next
►
Software Development
Explore the Details on the Mandelbrot Set
Because of the increase in the computational speed, computations that take a long time can now be computed in real time.
Explore details of the Mandelbrot set.
Because the computation is fast, visualizing the result is interactive.
Since
Mathematica
syntax is used, the turnaround speed is fast.
In[1]:=
X
mandelComp = Compile[{{c, _Complex}}, Module[{num = 1}, FixedPoint[(num++; #^2 + c) &, 0, 800, SameTest > (Re[#]^2 + Im[#]^2 >= 4 &)]; num], CompilationTarget > "C", RuntimeAttributes > {Listable}, Parallelization > True]; With[{x = 0, y = 1, draghold = {0.0524687, 0.749809}}, Panel[ Module[{dragstart = {0, 0}, dragval = {0, 0}, xrange, yrange, m = 10.2, scale = 0.000850147}, {xshift, yshift} = (dragstart  dragval + draghold) {1, 1}; {ylo, yhi} = yshift + scale*{1, 1}; {xlo, xhi} = xshift + scale*{1, 1}; xrange = {b, xlo, xhi, .0025 scale}; yrange = {a, ylo, yhi, .0025*scale}; data = Table[a + I b, Evaluate[yrange], Evaluate[xrange]]; ArrayPlot[mandelComp[data], ImageSize > 300] ] ] ]
Out[1]=
In[2]:=
X
mandelComp = Compile[{{c, _Complex}}, Module[{num = 1}, FixedPoint[(num++; #^2 + c) &, 0, 30, SameTest > (Re[#]^2 + Im[#]^2 >= 4 &)]; num], CompilationTarget > "C", RuntimeAttributes > {Listable}, Parallelization > True]; doPlotDrag[{x_, y_}] := Panel[ DynamicModule[{dragstart = {0, 0}, dragval = {0, 0}, draghold = {x, y}, xrange, yrange, m = Log[2, 1.5], scale = 1.5}, Column[{ Row[{"Zoom ", Slider[Dynamic[m, Function[scale = 2.^#; m = #]], {1, 50}], Dynamic[m]}], EventHandler[ Dynamic[{xshift, yshift} = (dragstart  dragval + draghold) {1, 1}; {ylo, yhi} = yshift + scale*{1, 1}; {xlo, xhi} = xshift + scale*{1, 1}; xrange = {b, xlo, xhi, .01 scale}; yrange = {a, ylo, yhi, .01*scale}; data = Table[a + I b, Evaluate[yrange], Evaluate[xrange]]; ArrayPlot[mandelComp[data], ImageSize > 300]], "MouseDown" :> (dragval = dragstart = scale*MousePosition["GraphicsScaled"]), "MouseDragged" :> (dragval = scale*MousePosition["GraphicsScaled"]), "MouseUp" :> (draghold = draghold + dragstart  dragval; dragstart = dragval = {0, 0})]}]] ] doPlotDrag[{0, 1}]
Out[2]=
In[3]:=
X
mandelComp = Compile[{{c, _Complex}, {ii, _Real}}, Module[{num = 1}, FixedPoint[(num++; #^ii + c) &, 0, 30, SameTest > (Re[#]^2 + Im[#]^2 >= 4 &)]; num], CompilationTarget > "C", RuntimeAttributes > {Listable}, Parallelization > True]; doPlotDrag[{x_, y_}] := Panel[ DynamicModule[{dragstart = {0, 0}, dragval = {0, 0}, draghold = {x, y}, xrange, yrange, m = Log[2, 1.5], scale = 2.0, ii = 2.0}, Column[{ Row[{"Power ", Slider[Dynamic[ii], {1.0, 10.0, 0.001}], Dynamic[ii]}], Row[{"Zoom ", Slider[Dynamic[m, Function[scale = 2.^#; m = #]], {1, 50}], Dynamic[m]}], EventHandler[ Dynamic[{xshift, yshift} = (dragstart  dragval + draghold) {1, 1}; {ylo, yhi} = yshift + scale*{1, 1}; {xlo, xhi} = xshift + scale*{1, 1}; xrange = {b, xlo, xhi, .01 scale}; yrange = {a, ylo, yhi, .01*scale}; data = Table[a + I b, Evaluate[yrange], Evaluate[xrange]]; ArrayPlot[mandelComp[data, ii], ImageSize > 300]], "MouseDown" :> (dragval = dragstart = scale*MousePosition["GraphicsScaled"]), "MouseDragged" :> (dragval = scale*MousePosition["GraphicsScaled"]), "MouseUp" :> (draghold = draghold + dragstart  dragval; dragstart = dragval = {0, 0})]}]] ] doPlotDrag[{0, 1}]
Out[3]=