(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.2' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing 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[ 28071, 813]*) (*NotebookOutlinePosition[ 28749, 836]*) (* CellTagsIndexPosition[ 28705, 832]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ "Interactive Function Manipulation for ", StyleBox["Mathematica", FontSlant->"Italic"], " 5.2", StyleBox["\n", FontSize->12], StyleBox["(and Earlier Versions)", FontSize->12, FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}] }], "Title", FontFamily->"Arial"], Cell[TextData[{ StyleBox["Andreas Lauschke\n", FontSize->16, FontWeight->"Bold"], StyleBox[ButtonBox["mooniac@gmail.com", ButtonData:>{ URL[ "mailto:mooniac@gmail.com"], None}, ButtonStyle->"Hyperlink"], FontSize->12] }], "Subtitle", FontFamily->"Arial"], Cell[TextData[{ "The following ", StyleBox["Mathematica", FontSlant->"Italic"], " functions demonstrate the use of methods from Java Swing to create an \ interactive environment for function manipulation. They are based on the \ J/Link Java connectivity package and use Java Swing code in ", StyleBox["Mathematica", FontSlant->"Italic"], "." }], "Text", FontFamily->"Arial"], Cell[CellGroupData[{ Cell[TextData[StyleBox["Discussion", FontSize->16, FontWeight->"Bold"]], "Section", FontFamily->"Arial"], Cell[TextData[{ "The function ", StyleBox["manipulate", "Input"], " takes at least two arguments, the first argument is the expression to be \ evaluated for various settings of the slider(s), which are defined in the \ second and possibly more argument(s). The entire function is wrapped in a ", StyleBox["JavaBlock", "Input"], " to ensure that all temporary Java objects that are created for this task \ are released after ", StyleBox["manipulate", "Input"], " is used. Everything is displayed on two JPanels, the first JPanel holds \ the slider(s) and the second JPanel (a MathGraphicsJPanel, inherited from \ JPanel), shows the output. For every slider a horizontal box is created that \ holds the slider, which is configured by setting various properties such as \ minimum and maximum tick spacing, etc., and a small border around it." }], "Text", FontFamily->"Arial"], Cell[TextData[{ "The ", StyleBox["manipulate", "Input"], " function makes use of the ", StyleBox["ImplementJavaInterface", "Input"], " function that J/Link provides, which is a very convenient way to \ implement practically every Java interface with method calls into the ", StyleBox["Mathematica", FontSlant->"Italic"], " kernel. In this case only the changeListener needs to be registered with \ the slider for which a stateChange event calls into a handler function (", StyleBox["computeexpr", "Input"], "). This event handler function then takes the expression to be manipulated \ and replaces the variables with the corresponding values that the slider(s) \ are set to, and sets the string representation of the resulting expression to \ the setMathCommand property of the MathGraphicsJPanel instance." }], "Text", FontFamily->"Arial"], Cell[TextData[{ "The code can easily be adapted to suit different needs, e. g. to place \ multiple sliders in a row/column layout, instead of the default layout that \ just displays one column of all sliders. Borders, sizes, colors, backgrounds, \ shapes, labels, etc., can be changed, basically everything that Java Swing \ supports in a manner that can be scripted in ", StyleBox["Mathematica", FontSlant->"Italic"], " can be used. One could add additional Swing components such as push \ buttons, spinners, radio buttons, drop-down menus, etc., provided the \ corresponding event listeners are registered and the event handlers are \ defined with ", StyleBox["ImplementJavaInterface", "Input"], "." }], "Text", FontFamily->"Arial"], Cell[TextData[{ "It is highly recommended to download the latest Java runtime and use it \ instead of the redistributable Java that ", StyleBox["Mathematica", FontSlant->"Italic"], " uses by default. Java 5 and Java 6 have much improved user-interface \ elements and use better internal Java code than the earlier versions 1.4.0 \ and 1.4.2 used as defaults in ", StyleBox["Mathematica", FontSlant->"Italic"], " versions 5.0 through 5.2. In that case change the variable ", StyleBox["javalocation", "Input"], " to the full path to the file java.exe (see example below in the code)." }], "Text", FontFamily->"Arial"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[StyleBox["The manipulate Function", FontSize->16, FontWeight->"Bold"]], "Section", FontFamily->"Arial"], Cell[BoxData[{ \(\(Off[General::"\"];\)\), "\n", \(\(Off[General::"\"];\)\)}], "Input"], Cell["This loads the package. ", "Text", FontFamily->"Arial"], Cell[BoxData[ \(<< JLink`\)], "Input"], Cell[TextData[{ "Set javalocation to the full path of the java.exe file of your Java \ installation if you want to specify a particular Java runtime. For example:\n\ \n", StyleBox["javalocation=\"E:\\\\Program \ Files\\\\Java\\\\jre1.5.0_06\\\\bin\\\\java.exe\";\n\ javalocation=\"E:\\\\Program \ Files\\\\Java\\\\jre1.5.0_08\\\\bin\\\\java.exe\";", FontFamily->"Courier"], "\n", StyleBox["javalocation=\"E:\\\\Program \ Files\\\\Java\\\\jre1.6.0\\\\bin\\\\java.exe\";", FontFamily->"Courier"], "\n \nLeave it \"\" to use the default one. " }], "Text", FontFamily->"Arial"], Cell[BoxData[ \(\(javalocation = "\<\>";\)\)], "Input"], Cell["\<\ We need the first argument of manipulate in a held form so that the string \ representation of the expression to be manipulated can be passed to the \ setMathCommand property.\ \>", "Text", FontFamily->"Arial"], Cell[BoxData[ \(\(SetAttributes[manipulate, HoldFirst];\)\)], "Input"], Cell["This defines the manipulate main function.", "Text", FontFamily->"Arial"], Cell[BoxData[ \(\(manipulate[expr_, tranges__] \ := \[IndentingNewLine]JavaBlock[\[IndentingNewLine]Module[{window, topPanel, plotPanel, title, computeexpr, tsliderListener, sliderlist, r1, r2, r3, trow, tslider, ranges = {tranges}}, \[IndentingNewLine]\[IndentingNewLine] (*\ Launch\ the\ Java\ runtime\ *) \[IndentingNewLine]If[ javalocation =!= "\<\>", InstallJava[CommandLine -> javalocation], InstallJava[]]; \[IndentingNewLine]\[IndentingNewLine] (*\ Create\ the\ window\ and\ position\ \(\(it\)\(.\)\)\ \ *) \[IndentingNewLine]window = JavaNew["\"]; \ \[IndentingNewLine]window@setLocation[1, 1]; \[IndentingNewLine]window@ setTitle["\"]; \[IndentingNewLine]\ \[IndentingNewLine] (*\ Create\ the\ two\ panels . \ topPanel\ holds\ the\ sliders . \ plotPanel\ holds\ the\ \(\(output\)\(.\)\)\ \ *) \[IndentingNewLine]topPanel = JavaNew["\"]; \[IndentingNewLine]topPanel@ setLayout[ JavaNew["\", topPanel, BoxLayout`YUAXIS]]; \[IndentingNewLine]plotPanel = JavaNew["\"]; \ \[IndentingNewLine]LoadJavaClass["\"]; \ \[IndentingNewLine]plotPanel@ setBackground[Color`white]; \[IndentingNewLine]plotPanel@ setPreferredSize[ JavaNew["\", 500, 500]]; \[IndentingNewLine]\[IndentingNewLine] (*\ Add\ the\ two\ panels\ to\ the\ top\ and\ bottom\ of\ the\ \ \(\(window\)\(.\)\)\ \ *) \[IndentingNewLine]LoadJavaClass["\"]; \ \[IndentingNewLine]window@\(getContentPane[]@ add[topPanel, ReturnAsJavaObject[ BorderLayout`NORTH]]\); \ \[IndentingNewLine]window@\(getContentPane[]@ add[plotPanel, ReturnAsJavaObject[ BorderLayout`SOUTH]]\); \[IndentingNewLine]\ \[IndentingNewLine] (*\ The\ following\ Table\ creates\ one\ slider\ per\ variable\ and\ \ sets\ properties\ for\ them\ \ *) \[IndentingNewLine]LoadJavaClass["\"]; \ \[IndentingNewLine]LoadJavaClass["\"]; \ \[IndentingNewLine]sliderlist = Table[\[IndentingNewLine]trow = Box`createHorizontalBox[]; \[IndentingNewLine]tslider = JavaNew["\", r1 = \(ranges[\([i]\)]\)[\([2]\)], r2 = \(ranges[\([i]\)]\)[\([3]\)], \ \(ranges[\([i]\)]\)[\([4]\)]]; \[IndentingNewLine]tslider@ setValue[\(ranges[\([i]\)]\)[\([2]\)]]; \ \[IndentingNewLine]tslider@setSnapToTicks[True]; \[IndentingNewLine]tslider@ setPaintLabels[True]; \[IndentingNewLine]tslider@ setPaintTicks[True]; \[IndentingNewLine]tslider@ setMinorTickSpacing[1]; \[IndentingNewLine]tslider@ setMajorTickSpacing[ If[\((r3 = r2 - r1)\) \[GreaterEqual] 20, Floor[r3/5], 1]]; \[IndentingNewLine]tslider@ setMaximumSize[ JavaNew["\", 400, 50]]; \[IndentingNewLine]tslider@ setBorder[ BorderFactory`createEmptyBorder[0, 20, 0, 20]]; \[IndentingNewLine]tsliderListener = ImplementJavaInterface["\\ ", {"\" \[Rule] ToString[computeexpr]}]; \[IndentingNewLine]tslider@ addChangeListener[ tsliderListener]; \ \[IndentingNewLine]\[IndentingNewLine]trow@ add[JavaNew["\", "\" <> ToString[\(ranges[\([i]\)]\)[\([1]\)]]]]; \ \[IndentingNewLine]trow@add[tslider]; \[IndentingNewLine]topPanel@ add[trow]; \[IndentingNewLine]tslider\[IndentingNewLine], \ {i, Length@ranges}]; \[IndentingNewLine]\[IndentingNewLine]window@ pack[]; \[IndentingNewLine]\[IndentingNewLine] (*\ Define\ the\ function\ to\ be\ called\ when\ the\ slider\ is\ \ \(\(dragged\)\(.\)\)\ *) \[IndentingNewLine]computeexpr[___] \ := \[IndentingNewLine]Module[{func, about, rng, sliderVal, series, plot}, \[IndentingNewLine]sliderVal = slider@getValue[]; \ \[IndentingNewLine]\[IndentingNewLine]Block[{$DisplayFunction = Identity}, \[IndentingNewLine]\(plot = \((Unevaluated[ expr])\) /. Table[\(ranges[\([i]\)]\)[\([1]\)] \[Rule] ToExpression[sliderlist[\([i]\)]@getValue[]], {i, Length@ ranges}];\)\[IndentingNewLine]]; \ \[IndentingNewLine]plotPanel@ setMathCommand[ ToString[plot, InputForm]]\[IndentingNewLine]]; \[IndentingNewLine] \ (*\ Now\ display\ the\ window\ in\ modal\ form\ *) \[IndentingNewLine]window@ setModal[]; \[IndentingNewLine]JavaShow[ window]; \[IndentingNewLine]computeexpr[]; \ \[IndentingNewLine]DoModal[];\[IndentingNewLine]]\[IndentingNewLine]];\)\)], \ "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[StyleBox["Examples", FontSize->16, FontWeight->"Bold"]], "Section", FontFamily->"Arial"], Cell[TextData[{ "The following examples demonstrate that almost anything that depends on \ numeric quantities that can be changed can be displayed with a manipulate. We \ use ", StyleBox["Graphics", "Input"], " objects, ", StyleBox["Graphics3D", "Input"], " objects, strings, numbers, and ", StyleBox["TableForm", "Input"], " output." }], "Text", FontFamily->"Arial"], Cell[CellGroupData[{ Cell["\<\ This example shows a simple rectangle with a color that is determined by the \ sliders.\ \>", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Graphics[{{RGBColor[a/100, b/100, c/100], Rectangle[{0, 0}, {3, 1}]}}], {a, 0, 100, 0}, {b, 0, 100, 0}, {c, 0, 100, 0}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Here we rotate a line clockwise around the origin, from 0 through 2 Pi.\ \>", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Graphics[{Line[{{0, 0}, {Sin[t/100], Cos[t/100]}}], Red, PointSize[0.02], Point[{Sin[t/100], Cos[t/100]}], Blue, Point[{0, 0}]}, PlotRange \[Rule] {{\(-1.2\), 1.2}, {\(-1.2\), 1.2}}, AspectRatio \[Rule] 1], {t, 0, Round[2 Pi\ 100], 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This example shows a Sine curve for which the sliders set frequency, phase \ shift, number of ", StyleBox["PlotPoints", "Input"], ", and color." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Plot[Sin[a\ x + b/10], {x, \(-Pi\), Pi}, PlotPoints \[Rule] c, PlotStyle \[Rule] Hue[d/100]], {a, 1, 4, 1}, {b, 0, Round[10\ 2\ Pi], 1}, {c, 25, 50, 25}, {d, 0, 100, 0}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This example is a 3-dim curve for which the sliders define frequency and \ number of ", StyleBox["PlotPoints", "Input"], "." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Plot3D[Sin[a\ x\ y], {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, PlotPoints \[Rule] b], {a, 1, 4, 1}, {b, 25, 50, 25}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "The following 3-dim Sine curve can be moved in the x-y plane with the \ first two sliders, the third slider sets the number of ", StyleBox["PlotPoints", "Input"], "." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Plot3D[Sin[x\ y], {x, \(-Pi\) + Pi\ a/100, Pi + Pi\ a/100}, {y, \(-Pi\) + Pi\ b/100, Pi + Pi\ b/100}, PlotPoints \[Rule] c], {a, 0, 100, 1}, {b, 0, 100, 1}, {c, 25, 50, 25}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This is a 3-dim ", StyleBox["Plot", "Input"], " that shows the unit disk at a value of 1 and 0 outside. The volume is ", StyleBox["Pi", "Input"], " when the slider is moved all the way to the right as can be seen with ", StyleBox["Integrate[Boole[x^2+y^2<1],{x,-1,1},{y,-1,1}]", "Input"] }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Plot3D[Boole[x^2 + y^2 < a/500], {x, \(-1\), 1}, {y, \(-1\), 1}, PlotPoints \[Rule] b], {a, 0, 500, 0}, {b, 25, 100, 25}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This shows a ", StyleBox["Plot", "Input"], " of the Bessel function of the first kind with a parameter determined by \ the slider." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[Plot[BesselJ[a, x], {x, 0, 20}], {a, 1, 10, 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ This example shows that the output doesn't have to be graphical, it can be a \ string.\ \>", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Part[{"\", "\", "\", "\", "\", "\", \ "\"}, a], {a, 1, 7, 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ This plot shows in realtime the solution of an ODE which depends on a \ parameter set by the slider.\ \>", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ Plot[Evaluate[ y[x] /. NDSolve[{\(y\^\[Prime]\)[x] == Sin[x^\((a/2)\)], y[0] == 0}, y[x], {x, 0, 10}]], {x, 0, 10}, PlotPoints \[Rule] 125, PlotRange \[Rule] All], {a, 0, 7, 0}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Notice how terrible the Taylor polynomial compares against the continued \ fraction expansion of the ", StyleBox["ArcTan", "Input"], " function. (In fact, to compute ", StyleBox["Pi", "Input"], " as ", StyleBox["4 ArcTan[1]", "Input"], " to 7 correct digits only 10 continued fraction terms are required, while \ even 10 ", StyleBox["million", FontSlant->"Italic"], " terms are not sufficient to attain the same accuracy when using the \ Taylor polynomial! This continued fraction expansion is identical to the \ (n+1,n+1)-Pad\[EAcute] expansion at 0.)" }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[{ \(\(arctancf[n_] := x/\((1 + Fold[\((x\ #2)\)^2\ /\((2\ #2 + 1 + #1)\) &, 0, Reverse@\(Range@n\)])\);\)\), "\[IndentingNewLine]", \(\(taylor[n_] := Sum[\((\(-1\))\)^k\ x^\((2 k + 1)\)/\((2 k + 1)\), {k, 0, n}];\)\), "\[IndentingNewLine]", \(manipulate[ Plot[Evaluate@{ArcTan@x, arctancf@n, taylor@n}, {x, \(-2\)\ Pi, 2 Pi}, PlotRange \[Rule] {\(-Pi\)/2, Pi/2}, PlotStyle \[Rule] {Red, Blue, Green}], {n, 1, 20, 1}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Here we plot a 3dim curve, parametrized by one variable.", \ "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}], Cell[BoxData[ \(manipulate[ ParametricPlot3D[{Cos[5 t/100], Sin[3 t/100], Sin[t/100]}, {t, 0.01, lim}, PlotPoints \[Rule] 300, PlotRange \[Rule] {{\(-1\), 1}, {\(-1\), 1}, {\(-1\), 1}}], {lim, 0, Round[100\ 2\ Pi], 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Here we expand ", StyleBox["n", "Input"], " terms of an algebraic expression." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[ \(manipulate[Expand[\((1 + a)\)^n], {n, 0, 50, 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Here we factor the expression ", StyleBox["x^n-1", "Input"], " of up to 50 terms." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[ \(manipulate[Factor[x^n - 1], {n, 0, 50, 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This outputs various functions of ", StyleBox["n", "Input"], " in a framed ", StyleBox["GridBox", "Input"], "." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[ \(manipulate[ FrameBox@GridBox[ Prepend[\({#, Fibonacci@#, Prime@#, PrimePi@#, 2^#} &\) /@ Range@n, {"\", "\", "\", \ "\", "\<2^n\>"}], RowLines \[Rule] True, ColumnLines \[Rule] True], {n, 1, 25, 1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This compares the Herglotz series of ", StyleBox["Pi Cot[Pi x]", "Input"], " with the exact function." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[{ \(\(herglotz[deg_] := 1/x + Sum[ 1/\((x + n)\) + 1/\((x - n)\), {n, 1, deg}];\)\), "\[IndentingNewLine]", \(manipulate[ Plot[{Pi\ Cot[x\ Pi], herglotz[n]}, {x, \(-4\) Pi, 4 Pi}, PlotStyle \[Rule] {Red, Blue}], {n, 1, 10, 1}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["GraphPlot works on disconnected graphs. ", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[{ \(<< DiscreteMath`GraphPlot`\), "\[IndentingNewLine]", \(manipulate[ If[n > 0, GraphPlot[Table[i \[Rule] Mod[i^2, n], {i, 0, n - 1}]], "\<\>"], {n, 0, 500, 1}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["This shows the n-Butterfly Graphs.", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[{ \(<< DiscreteMath`GraphPlot`\), "\[IndentingNewLine]", \(manipulate[ShowGraph@ButterflyGraph[n], {n, 1, 5, 1}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["This shows the n,k-DeBruijn Graphs.", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[{ \(<< DiscreteMath`GraphPlot`\), "\[IndentingNewLine]", \(manipulate[ ShowGraph@DeBruijnGraph[n, k], {n, 1, 3, 1}, {k, 1, 3, 1}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "By manipulating the ", StyleBox["ViewPoint", "Input"], " with the slider you can effectively rotate the 3d graphic." }], "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[ \(Off[Arg::"\"]; manipulate[ Plot3D[Arg[x + I\ y], {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, PlotPoints \[Rule] b, \ ViewPoint\ -> \ {5\ Cos[alpha/100], \ 5\ Sin[alpha/100], \ 2}, \ SphericalRegion -> True, \ \ Axes\ -> \ False], {alpha, 0, Round[2\ Pi\ 100], 0}, {b, 25, 75, 50}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ This example shows two curves the lengths of which are adjusted with the \ slider.\ \>", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell["warning: can be slow on slower machines!", "Text", FontFamily->"Arial"], Cell[BoxData[{ \(\(tfunc[a_, b_] := \((\[IndentingNewLine]Block[{$DisplayFunction = Identity}, \[IndentingNewLine]pl1 = ParametricPlot3D[{x + 1/10000, y + 1/10000, Arg[x + I\ y]}, {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, PlotPoints \[Rule] b]; \[IndentingNewLine]pl2 = ParametricPlot3D[{Pi\ \((\(-Cos@t\))\), Pi\ \((\(-Sin@t\))\), t - Pi + 0.01}, {t, 0, a + 1/10000}, PlotPoints \[Rule] b]; \[IndentingNewLine]pl3 = ParametricPlot3D[{1/2\ Pi\ \((\(-Cos@t\))\), 1/2\ Pi\ \((\(-Sin@t\))\), t - Pi + 0.01}, {t, 0, a + 1/10000}, PlotPoints \[Rule] b];\[IndentingNewLine]]; \[IndentingNewLine]Graphics3D[ Join[pl1[\([1]\)], {RGBColor[1. , 0. , 0. ], {Thickness[0.005], pl2[\([1]\)]}}, {RGBColor[1. , 0. , 0. ], {Thickness[0.005], pl3[\([1]\)]}}]]\[IndentingNewLine])\);\)\), "\n", \(manipulate[ tfunc[a/100, b], {a, 0, Floor[2\ Pi\ 100], 1}, {b, 25, 50, 25}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Several Fourier sum expansions of continuous and discontinuous functions.\ \>", "Subsubsection", CellDingbat->"\[FilledDiamond]", FontFamily->"Arial", FontWeight->"Plain"], Cell[BoxData[{ \(\(Off[NIntegrate::"\"];\)\), "\n", \(\(Off[NIntegrate::"\"];\)\)}], "Input"], Cell[BoxData[ \(\(fsum[f_, {x_Symbol, minusL_?NumericQ, L_?NumericQ}, m_Integer] := If[minusL == \(-L\), Chop[\((1/\((2*L)\))\)*NIntegrate[f, {x, \(-L\), L}] + \((1/L)\)* Sum[NIntegrate[f*Cos[n*Pi*x/L], {x, \(-L\), L}]* Cos[n*Pi*x/L] + NIntegrate[f*Sin[n*Pi*x/L], {x, \(-L\), L}]* Sin[n*Pi*x/L], {n, 1, m}]], Print["\"]; {}];\)\)], \ "Input"], Cell[BoxData[ \(With[{func = Abs@x}, manipulate[ Plot[Evaluate@{func, fsum[func, {x, \(-5\), 5}, n]}, {x, \(-5\), 5}, PlotStyle \[Rule] {Red, Blue}], {n, 0, 25, 1}]]\)], "Input"], Cell[BoxData[ \(With[{func = Piecewise[{{0, x < 0}}, x]}, manipulate[ Plot[Evaluate@{func, fsum[func, {x, \(-5\), 5}, n]}, {x, \(-5\), 5}, PlotRange \[Rule] All, PlotStyle \[Rule] {Red, Blue}], {n, 0, 25, 1}]]\)], "Input"], Cell[BoxData[ \(With[{func = Piecewise[{{0, x < \(-1\)}, {x + 1, x > \(-1\) && x < 0}, {1 - x^2, x > 0 && x < 1}, {0, x > 1}}, x]}, manipulate[ Plot[Evaluate@{func, fsum[func, {x, \(-2\), 2}, n]}, {x, \(-2\), 2}, PlotRange \[Rule] All, PlotStyle \[Rule] {Red, Blue}], {n, 0, 25, 1}]]\)], "Input"], Cell[BoxData[ \(With[{func = Piecewise[{{0, x < \(-1\)}, {1 - 2 x, x > \(-1\) && x < 0}, {1, x > 0 && x < 1}, {0, x > 1}}, x]}, manipulate[ Plot[Evaluate@{func, fsum[func, {x, \(-2\), 2}, n]}, {x, \(-2\), 2}, PlotRange \[Rule] All, PlotStyle \[Rule] {Red, Blue}], {n, 0, 50, 1}]]\)], "Input"], Cell["\<\ Note that due to its construction the Fourier series is extended periodically \ beyond the interval over which it was created.\ \>", "Text", FontFamily->"Arial"], Cell[BoxData[ \(With[{func = Piecewise[{{0, x < \(-1\)}, {1 - 2 x, x > \(-1\) && x < 0}, {1, x > 0 && x < 1}, {0, x > 1}}, x]}, manipulate[ Plot[Evaluate@{func, fsum[func, {x, \(-2\), 2}, n]}, {x, \(-6\), 6}, PlotRange \[Rule] All, PlotStyle \[Rule] {Red, Blue}], {n, 0, 50, 1}]]\)], "Input"] }, Open ]] }, Open ]] }, Open ]] }, FrontEndVersion->"5.2 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 688}}, WindowSize->{1016, 661}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, StyleDefinitions -> "Default.nb" ] (******************************************************************* 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[CellGroupData[{ Cell[1776, 53, 319, 12, 122, "Title"], Cell[2098, 67, 286, 10, 60, "Subtitle"], Cell[2387, 79, 394, 11, 52, "Text"], Cell[CellGroupData[{ Cell[2806, 94, 110, 3, 68, "Section"], Cell[2919, 99, 888, 16, 112, "Text"], Cell[3810, 117, 864, 17, 111, "Text"], Cell[4677, 136, 750, 15, 91, "Text"], Cell[5430, 153, 639, 14, 72, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[6106, 172, 123, 3, 68, "Section"], Cell[6232, 177, 113, 2, 50, "Input"], Cell[6348, 181, 63, 1, 33, "Text"], Cell[6414, 184, 42, 1, 30, "Input"], Cell[6459, 187, 597, 15, 147, "Text"], Cell[7059, 204, 59, 1, 30, "Input"], Cell[7121, 207, 222, 5, 52, "Text"], Cell[7346, 214, 74, 1, 30, "Input"], Cell[7423, 217, 81, 1, 33, "Text"], Cell[7507, 220, 5600, 100, 1370, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[13144, 325, 108, 3, 68, "Section"], Cell[13255, 330, 383, 11, 53, "Text"], Cell[CellGroupData[{ Cell[13663, 345, 245, 7, 29, "Subsubsection"], Cell[13911, 354, 192, 4, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[14140, 363, 229, 6, 29, "Subsubsection"], Cell[14372, 371, 327, 6, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[14736, 382, 313, 9, 30, "Subsubsection"], Cell[15052, 393, 238, 4, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[15327, 402, 293, 9, 30, "Subsubsection"], Cell[15623, 413, 170, 3, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[15830, 421, 335, 9, 30, "Subsubsection"], Cell[16168, 432, 253, 5, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[16458, 442, 462, 11, 48, "Subsubsection"], Cell[16923, 455, 181, 3, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[17141, 463, 300, 9, 30, "Subsubsection"], Cell[17444, 474, 91, 1, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[17572, 480, 244, 7, 29, "Subsubsection"], Cell[17819, 489, 154, 3, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[18010, 497, 258, 7, 29, "Subsubsection"], Cell[18271, 506, 273, 6, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[18581, 517, 738, 19, 64, "Subsubsection"], Cell[19322, 538, 547, 11, 90, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[19906, 554, 208, 5, 29, "Subsubsection"], Cell[20117, 561, 272, 5, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[20426, 571, 203, 7, 30, "Subsubsection"], Cell[20632, 580, 81, 1, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[20750, 586, 207, 7, 30, "Subsubsection"], Cell[20960, 595, 75, 1, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[21072, 601, 240, 9, 30, "Subsubsection"], Cell[21315, 612, 316, 6, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[21668, 623, 227, 7, 30, "Subsubsection"], Cell[21898, 632, 314, 7, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[22249, 644, 146, 3, 29, "Subsubsection"], Cell[22398, 649, 221, 5, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[22656, 659, 140, 3, 29, "Subsubsection"], Cell[22799, 664, 148, 2, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[22984, 671, 141, 3, 29, "Subsubsection"], Cell[23128, 676, 171, 3, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[23336, 684, 241, 7, 30, "Subsubsection"], Cell[23580, 693, 362, 7, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[23979, 705, 196, 6, 29, "Subsubsection"], Cell[24178, 713, 79, 1, 33, "Text"], Cell[24260, 716, 1174, 21, 210, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[25471, 742, 187, 5, 29, "Subsubsection"], Cell[25661, 749, 119, 2, 50, "Input"], Cell[25783, 753, 497, 9, 130, "Input"], Cell[26283, 764, 208, 4, 50, "Input"], Cell[26494, 770, 263, 5, 50, "Input"], Cell[26760, 777, 365, 7, 50, "Input"], Cell[27128, 786, 362, 7, 50, "Input"], Cell[27493, 795, 173, 4, 33, "Text"], Cell[27669, 801, 362, 7, 50, "Input"] }, Open ]] }, Open ]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)