(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-5, 12, "Courier"; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R65535, L-5, 12, "Courier"; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B65535, L-5, 12, "Courier"; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Geneva"; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = leftheader, inactive, L2, 12, "Times"; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; fontset = leftfooter, inactive, L2, 12, "Times"; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; paletteColors = 128; automaticGrouping; currentKernel; ] :[font = subtitle; inactive; preserveAspect; startGroup] Programming :[font = text; inactive; preserveAspect] Examples of simple programs: Construct Hilbert matrix: :[font = input; preserveAspect] Hilbert[n_] := Table[1/(i+j-1), {i,n}, {j,n}] :[font = text; inactive; preserveAspect] Characteristic polynomial: :[font = input; preserveAspect] CharPoly[m_, x_] := Det[m - x IdentityMatrix[Length[m]]] /; MatrixQ[m] :[font = text; inactive; preserveAspect] Calculate next prime: :[font = input; preserveAspect] NextPrime[n_Integer] := Module[{k=n}, While[!PrimeQ[k], k++]; Return[k]] :[font = text; inactive; preserveAspect] Calculate statistics of a list: :[font = input; preserveAspect] Mean[list_List] := Apply[Plus, list] / Length[list] :[font = input; preserveAspect] Variance[list_List] := Mean[ (list - Mean[list])^2 ] :[font = input; preserveAspect] Quantile[list_List, q_] := Part[ Sort[list], -Floor[-q Length[list]] ] /; 0 < q < 1 :[font = text; inactive; preserveAspect] Generate 1D random walk: :[font = input; preserveAspect] RandomWalk[n_Integer] := FoldList[Plus, 0, Table[Random[ ] - 1/2, {n}]] :[font = text; inactive; preserveAspect] Generate continued fraction: :[font = input; preserveAspect] ContinuedFraction[x_Real, n_Integer] := Floor[ NestList[ Function[{u}, 1/(u-Floor[u])], x, n-1] ] :[font = text; inactive; preserveAspect] Generate Jacobian matrix: :[font = input; preserveAspect] Jacobian[funs_List, vars_List] := Outer[D, funs, vars] :[font = input; preserveAspect] Laplace[c_, t_, s_] := c/s /; FreeQ[c,t] Laplace[a_ + b_, t_, s_] := Laplace[a, t, s] /; FreeQ[c,t] Laplace[t_^n_., t_, s_] := n!/s^(n+1) /; (FreeQ[c,t] && n > 0) Laplace[a_. Exp[b_. + c_. t_], t_, s_] := Laplace[a Exp[b], t, s - c] /; FreeQ[{b.c}. t] :[font = input; preserveAspect] RunEncode[{rest___Integer, same:(n_Integer)..}] := Append[ RunEncode[{rest}], {n, Length[{same}]} ] RunEncode[ { }] := { } :[font = input; preserveAspect] PolarPlot[r_, {t_, tmin_, tmax_}] := ParametricPlot[{r Cos[t], r Sin[t]}, {t, tmin, tmax}, AspectRatio -> Automatic] :[font = input; preserveAspect] RootPlot[poly_, z_] := ListPlot[{Re[z], Im[z]} /. NSolve[poly == 0, z]] /; PolynomialQ[poly, z] :[font = input; preserveAspect] FilePlot3D[file_String] := ListPlot3D[ReadList[file, Number, RecordLists -> True] ] :[font = input; preserveAspect; endGroup] Where[s_String] := Select[ FileNames[ ], (Length[FindList[#, s, 1]] >0)& ] ^*)