(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 13577, 427]*) (*NotebookOutlinePosition[ 14629, 461]*) (* CellTagsIndexPosition[ 14585, 457]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData["\nChapter Five:\n\nIterative Complex Graphics"], "Title", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData["5.1 Complex Cantor Sets"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "ComplexBase1[b_, m_] := Block[{i = 1},\n\tShow[Graphics[\n\t\t\t\ Map[Point[{Re[#], Im[#]}] &, \n\t\t\t\tNest[Join[#, # + b^i++] &, {0}, m]]],\n\ PlotRange -> All, Axes -> Automatic, AspectRatio -> 1]]"], "Input", AspectRatioFixed->True], Cell[TextData["ComplexBase1[.5 + .5I, 11]//Timing"], "Input", AspectRatioFixed->True], Cell[TextData[ "ComplexBase[b_, m_] := Block[{i = 1,\n\t\tpowers = Map[{Re[#], Im[#]} &, b ^ \ Range[m + 1]]},\n Show[Graphics[Map[Point, \n Nest[\n Join[#, # /. \ {x_Real, y_Real} -> {x, y} + powers[[i++]]] &,\n {powers[[1]]}, m]]],\n \ PlotRange -> All, Axes -> Automatic, AspectRatio -> 1]]"], "Input", AspectRatioFixed->True], Cell[TextData["ComplexBase[.5 + .5I, 11]//Timing"], "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData[ "m = 3\nFlatten[Outer @@ Prepend[Table[{0, 1}, {m}], List], \n\t\tm - 1] \ //MatrixForm"], "Input", AspectRatioFixed->True], Cell[OutputFormData[ "\<\ MatrixForm[{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}}]\ \>", "\<\ 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["Map[{Re[#], Im[#]} &, b^Range[m]] //MatrixForm"], "Input", AspectRatioFixed->True], Cell[OutputFormData[ "\<\ MatrixForm[{{Re[b], Im[b]}, {Re[b^2], Im[b^2]}, {Re[b^3], \ Im[b^3]}}]\ \>", "\<\ Re[b] Im[b] 2 2 Re[b ] Im[b ] 3 3 Re[b ] Im[b ]\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[TextData[ "FastComplexBase[b_, m_] := Show[Graphics[Point /@ \n (Flatten[Outer @@ \ Prepend[Table[{0., 1.}, {m}], List], m - 1].\n Map[{Re[#], Im[#]} &, \ b^Range[m]])],\n PlotRange -> All, Axes -> Automatic, AspectRatio -> 1]"], "Input", AspectRatioFixed->True], Cell[TextData["FastComplexBase[.5+.5I, 11]//Timing"], "Input", AspectRatioFixed->True], Cell[TextData[ "FastComplexBase[z_, m_] := Show[Graphics[Point /@ \n ((temp = \ -MemoryInUse[];\n Flatten[Outer @@ Prepend[Table[{0., 1.}, {m}], List], m - \ 1]).\n Map[{Re[#], Im[#]} &, z ^ Range[m]])],\n PlotRange -> (Print[temp \ + MemoryInUse[]]; All),\n Axes -> Automatic, AspectRatio -> 1] "], "Input", AspectRatioFixed->True], Cell[TextData[ "$Display = OpenWrite[\"psfile\"]\nComplexBase[.8 + .2 I, 15, {{1, 2}, None}, \ \n\t\t{{-.7, 2.5}, {-.2, 2.8}}];\nClose[\"psfile\"]\n$Display = \"stdout\";"], "Input", AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["5.2 Iterated Function Systems"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "top = {.5, Sqrt[3.]/2}\nf1[x_] := .5 x; \nf2[x_] := .5(x + {1,0}); \nf3[x_] \ := .5(x + top)\n\nf[x_] := {f1,f2,f3}[[Random[Integer, {1,3}]]][x]\n\n\ ChaosGame[start_, n_] :=\nShow[Graphics[Map[Point, NestList[f, start, n]]],\n\ \tPlotRange->{{0, 1}, {0, .87}}, Axes->Automatic,\n\tAspectRatio->.87,\n\t\ Ticks->{{.25, .5, .75, 1}, {.25, .5, .75}}]"], "Input", AspectRatioFixed->True], Cell[TextData["ChaosGame[{.1, .8}, 3^8]"], "Input", AspectRatioFixed->True], Cell[TextData["ChaosGame[{.4, .3}, 3^8]"], "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData[ "Clear[f]\nf[A_] :=\n0.5 Union[A, Map[# + {1,0} &, A], Map[# + \ {.5,Sqrt[3.]/2} &, A]]\n\nChaosGameDeterministic[start_, n_] := \ Show[Graphics[Map[Point,\n\tNest[f, {start}, n]]],\n\tPlotRange->{{0,1}, \ {0,.87}}, Axes->Automatic,\n\tAspectRatio->.87, Ticks->{{.25,.5,.75,1}, \ {.25,.5,.75,1}}]\n\nDo[ChaosGameDeterministic[{.1, .8}, i], {i, 0, 8}]"], "Input", AspectRatioFixed->True], Cell[TextData[ "distinctsubstrings[n_] := Length[Union[Partition[\n Table[Random[Integer, \ {1, 3}], {n}], 10, 1]]]"], "Input", AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["distinctsubstrings[100]"], "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ 91\ \>", "\<\ 91\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[ "5.3 Biasing the Chaos Game: Barnsley\[CloseCurlyQuote]s Fern"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Clear[f]\ntop = {.5, Sqrt[3.]/2}\nf1[x_] := .5 x\nf2[x_] := .5(x + {1,0})\n\ f3[x_] := .5(x + top)\nf[x_] := Which[(r = Random[Integer,{1,4}]) <= 2, \ f3[x],\n\t\t\t\tr == 3, f1[x], r == 4, f2[x]]\n\nBiasedChaosGame[start_, n_] \ := \n Show[Graphics[Map[Point, NestList[f, start, n]], \n PlotRange->{{0, \ 1}, {0, .87}}, AspectRatio->.87]]"], "Input", AspectRatioFixed->True], Cell[TextData["BiasedChaosGame[{0,0},100]"], "Input", AspectRatioFixed->True], Cell[TextData[ "MatrixNorm[A_] := Max[Sqrt[Eigenvalues[Transpose[A].A]]]"], "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData[ "{A1, A2, A3, A4} = { \t{{.85, .04}, {-.04, .85}},\n\t\t\t\t\t{{-.15, \ .28}, { .26, .24}},\n\t\t\t\t\t{{0.2, -.26}, { .23, .22}},\n\t\t\t\t\t{{0, \ 0 }, { 0, .16}} };\n\nMap[MatrixNorm, {A1, A2, A3, A4}]"], "Input", AspectRatioFixed->True], Cell[OutputFormData[ "\<\ {0.8509406559801923109, 0.3791517719540821999, 0.3407118123825710023, 0.16}\ \>", "\<\ {0.850941, 0.379152, 0.340712, 0.16}\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData[ "{fixed1, fixed2, fixed3, fixed4} = {\n Inverse[A1 - \ IdentityMatrix[2]] . {0, -1.6 },\n Inverse[A2 - IdentityMatrix[2]] . \ {0, -.44},\n Inverse[A3 - IdentityMatrix[2]] . {0, -1.6 },\n \ Inverse[A4 - IdentityMatrix[2]] . {0, 0 } }"], "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ {{2.655601659751037345, 9.958506224066390043}, {0.1537693459810284573, 0.6315526709935097352}, {-0.6083650190114068442, 1.871892366188944136}, {0, 0}}\ \>", "\<\ {{2.6556, 9.95851}, {0.153769, 0.631553}, {-0.608365, 1.87189}, {0, \ 0}}\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[TextData[ "BarnsleyFern[n_] := \n Show[Graphics[Map[Point, NestList[\n Which[\n \ (r = Random[Integer, {1,100}]) <= 85, A1.# + {0, 1.6},\n \ r <= 92, A2.# + {0, .44},\n r \ <= 99, A3.# + {0, 1.6},\n r == 100, A4.# ] \ &,\n \t{0,0}, n]], PlotRange->All]]\n"], "Input", AspectRatioFixed->True], Cell[TextData["following two cells take a lot of time"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["BarnsleyFern[28000] "], "Input", AspectRatioFixed->True], Cell[TextData["BarnsleyFern[10000] "], "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData[ "Clear[f1, f2, f3, f4]\nf1[{x_, y_}] := A1.{x,y} + {0, 1.6} /; Length[x] != 2\ \nf1[set:{_List..}] := Map[f1, set]\n\nf2[{x_,y_}] := A2.{x,y} + {0, .44} /; \ Length[x] != 2\nf2[set:{_List..}] := Map[f2, set]\n\nf3[{x_,y_}] := A3.{x,y} \ + {0, 1.6}/; Length[x] != 2\nf3[set:{_List..}] := Map[f3, set]\n\n\ f4[{x_,y_}] := A4.{x,y}/; Length[x] != 2\nf4[set:{_List..}] := Map[f4, set]"], "Input", AspectRatioFixed->True], Cell[TextData[ "region = {fixed1, f2[fixed1], {0,0}, f3[fixed1], fixed1}\n\ Show[Graphics[Map[Line, NestList[f1, region, 10]]],\nAspectRatio->1, \ Axes->Automatic];"], "Input", AspectRatioFixed->True], Cell[TextData[ "\nregion1 = {fixed1, f2[fixed1], f4[fixed1], f3[fixed1], fixed1}\nspine = \ NestList[f1, {0,0}, 35]\nShow[Graphics[{\n\tThickness[.001], Map[Line, \ NestList[f2, region1, 2]],\n\tDashing[{.01}], Map[Line, NestList[f2, \ spine,2]]}],\nAspectRatio->1, Axes->Automatic];"], "Input", AspectRatioFixed->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[TextData["5.4 Julia Sets"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "ComplexTrajectory[z_, c_, init_:0, n_] := \nShow[Graphics[{PointSize[.025],\n\ \tPoint[{Re[z],Im[z]}], Thickness[.0001],\n\tLine[Map[{Re[#],Im[#]} &,\n\t \ NestList[#^2 + c &,\n\t\t\tNest[#^2+c &,\n\t\t\t\tIf[Precision[z] < Infinity, \ z, N[z]], init],\n\t\t\tn]]]}],\n\tPlotRange->All, Axes->Automatic]"], "Input",\ AspectRatioFixed->True], Cell[TextData[ "ComplexTrajectory[ -0.32 + 0.5I,-0.12256117 + 0.74486177I, 40];"], "Input", AspectRatioFixed->True], Cell[TextData[ "JuliaIIM[c_, n_] := Show[Graphics[\n Map[{Point[{Re[#], Im[#]}], \ Point[-{Re[#], Im[#]}]} &,\n Drop[NestList[If[Random[Integer] == 1, 1, -1] \ Sqrt[# - c] &,\n\t 0.2, n + 50], 50]]]]"], "Input", AspectRatioFixed->True], Cell[TextData["JuliaIIM[0.390541 - 0.586788I, 1400];"], "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData[ "chop[z_] := (Round[600 Re[z]] + I Round[600 Im[z]]) / 600.\nAttributes[chop] \ = Listable"], "Input", AspectRatioFixed->True], Cell[TextData["chop[.75024652465 + .15146426I]"], "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ 0.75 + 0.1516666666666666667*I\ \>", "\<\ 0.75 + 0.151667 I\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[TextData[ "JuliaIIMHistogram[c_, n_] := Show[Graphics3D[Map[\n Line[{{Re[#], Im[#], \ 1}, {Re[#], Im[#], Count[temp, #]}}] &,\n Union[temp = chop@Drop[NestList[\n\ If[Random[Integer] == 1, 1, -1] Sqrt[# - c] &, .2, n+40], \t\t\t\t\t \ 40]]]],\n Boxed->False, BoxRatios->{1,1,1/3}, PlotRange->All]"], "Input", AspectRatioFixed->True], Cell[TextData[ "\nJuliaIIMHistogram[-0.1 + 0.8 I, 1000]; (* 10000 in book *)"], "Input", AspectRatioFixed->True], Cell[TextData[ "JuliaIIMf[r_, n_] := Show[Graphics[\n Map[{Point[{Re[#], Im[#]}], \ Point[{Re[#], -Im[#]}],\n Point[{1-Re[#], Im[#]}], Point[{1-Re[#], \ -Im[#]}]} &,\n Drop[NestList[.5 + If[Random[Integer]==1, 1, -1] * \n\t\t \ Sqrt[.25 - #/r] &, 0.2, n + 50], 50]]],\nAxes->Automatic, \ Ticks->{{0,1}, Automatic}]"], "Input", AspectRatioFixed->True], Cell[TextData["JuliaIIMf[3, 500];\t(* 5000 in book *)"], "Input", AspectRatioFixed->True], Cell[TextData[ "orbitcheck[z_, c_, iters_] := (s = z; i = 0;\n While[++i <= iters && Abs[s \ = s^2 + c] < 2];\n\tIf[i == iters+1, {Re[z], Im[z]}*#& /@ {1,-1}, {}])\n\n(* \ One of x0, y0 should be 0 *)\nFilledJuliaSet[c_, meshx_Integer, \ meshy_Integer,\n x0_, x1_, y0_, y1_, iters_:20] := \n\n\ Show[Graphics[{PointSize[.002], Point /@ Flatten[\n\nOuter[orbitcheck[#1 + I \ #2, N[c], iters]&,\n Range[x0, x1, (x1-x0)/meshx], Range[y0, y1, \ (y1-y0)/meshy]],\n\t\t 2]}],\n\ AspectRatio->(ymax=Max[Abs[{y0,y1}]])/(xmax=Max[Abs[{x0,x1}]]),\n\ PlotRange->{{-xmax,xmax}, {-ymax,ymax}}]"], "Input", AspectRatioFixed->True], Cell[TextData[ "following cells take a very long time and use lots of memory!!!!!!!"], "Text",\ Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "c = -.12256117 + .74486177 I (* rabbit *)\nFilledJuliaSet[c, 230, 195, \ -1.31, .52, 0, 1.11, 30]"], "Input", AspectRatioFixed->True], Cell[TextData[ "\nc =.32 + .043 I (* 11-cycle dragon *) \nFilledJuliaSet[c, 160, 210, -.85, \ .80, 0, 1.12, 80]"], "Input", AspectRatioFixed->True], Cell[TextData[ "\nc = -0.390541 - 0.586788*I (* Siegel disk *)\nFilledJuliaSet[c, 230, 165, \ -.77, 1.42, 0, 1.03, 30]"], "Input", AspectRatioFixed->True], Cell[TextData["following cell uses program from the Appendix"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["FilledJuliaSetReal[3, 140, 84, .5, .3, 60];"], "Input", AspectRatioFixed->True] }, Closed]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 832}, {0, 604}}, WindowToolbars->{}, CellGrouping->Manual, WindowSize->{520, 509}, WindowMargins->{{40, Automatic}, {Automatic, 7}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, MacintoshSystemPageSetup->"\<\ 00<0001804P000000]P2:?oQon82n@960dL5:0?l0080001804P000000]P2:001 0000I00000400`<300000BL?00400@00000000000000060001T1T00000000000 00000000000000000000000000000000\>" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1709, 49, 120, 2, 216, "Title", Evaluatable->False], Cell[CellGroupData[{ Cell[1854, 55, 100, 2, 51, "Section", Evaluatable->False], Cell[1957, 59, 258, 4, 102, "Input"], Cell[2218, 65, 87, 1, 27, "Input"], Cell[2308, 68, 341, 5, 162, "Input"], Cell[2652, 75, 86, 1, 27, "Input"], Cell[CellGroupData[{ Cell[2763, 80, 140, 3, 57, "Input"], Cell[2906, 85, 284, 22, 70, "Output", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[3227, 112, 99, 1, 24, "Input"], Cell[3329, 115, 249, 15, 70, "Output", Evaluatable->False] }, Closed]], Cell[3593, 133, 276, 5, 99, "Input"], Cell[3872, 140, 88, 1, 27, "Input"], Cell[3963, 143, 346, 6, 117, "Input"], Cell[4312, 151, 211, 4, 87, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[4560, 160, 106, 2, 31, "Section", Evaluatable->False], Cell[4669, 164, 402, 6, 192, "Input"], Cell[5074, 172, 77, 1, 27, "Input"], Cell[5154, 175, 77, 1, 27, "Input"], Cell[CellGroupData[{ Cell[5256, 180, 406, 7, 207, "Input"], Cell[5665, 189, 153, 3, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[5855, 197, 76, 1, 24, "Input"], Cell[5934, 200, 106, 6, 70, "Output", Evaluatable->False] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[6089, 212, 138, 3, 31, "Section", Evaluatable->False], Cell[6230, 217, 395, 6, 192, "Input"], Cell[6628, 225, 79, 1, 27, "Input"], Cell[6710, 228, 110, 2, 42, "Input"], Cell[CellGroupData[{ Cell[6845, 234, 268, 4, 102, "Input"], Cell[7116, 240, 217, 8, 70, "Output", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[7370, 253, 322, 5, 144, "Input"], Cell[7695, 260, 332, 10, 70, "Output", Evaluatable->False] }, Closed]], Cell[8042, 273, 409, 6, 189, "Input"], Cell[8454, 281, 112, 2, 30, "Text", Evaluatable->False], Cell[8569, 285, 73, 1, 27, "Input"], Cell[8645, 288, 73, 1, 27, "Input"], Cell[CellGroupData[{ Cell[8743, 293, 437, 7, 192, "Input"], Cell[9183, 302, 202, 4, 70, "Input"], Cell[9388, 308, 323, 5, 70, "Input"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[9760, 319, 91, 2, 31, "Section", Evaluatable->False], Cell[9854, 323, 359, 6, 162, "Input"], Cell[10216, 331, 117, 2, 42, "Input"], Cell[10336, 335, 243, 4, 102, "Input"], Cell[10582, 341, 90, 1, 27, "Input"], Cell[CellGroupData[{ Cell[10697, 346, 143, 3, 57, "Input"], Cell[10843, 351, 84, 1, 27, "Input"], Cell[10930, 354, 150, 7, 25, "Output", Evaluatable->False] }, Closed]], Cell[11095, 364, 354, 5, 114, "Input"], Cell[11452, 371, 114, 2, 57, "Input"], Cell[11569, 375, 384, 6, 162, "Input"], Cell[11956, 383, 91, 1, 27, "Input"], Cell[12050, 386, 677, 10, 282, "Input"], Cell[12730, 398, 144, 4, 30, "Text", Evaluatable->False], Cell[12877, 404, 151, 3, 42, "Input"], Cell[13031, 409, 149, 3, 57, "Input"], Cell[13183, 414, 157, 3, 57, "Input"], Cell[13343, 419, 119, 2, 30, "Text", Evaluatable->False], Cell[13465, 423, 96, 1, 27, "Input"] }, Closed]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)