home *** CD-ROM | disk | FTP | other *** search
-
- (*********************************************************************
-
- Adapted from
- Roman E. Maeder: Programming in Mathematica,
- Second Edition, Addison-Wesley, 1991.
-
- *********************************************************************)
-
-
- BeginPackage["RandomWalk`"]
-
- RandomWalk::usage = "RandomWalk[n] plots a random walk of length n."
-
- Begin["`Private`"]
-
- range = N[{0, 2Pi}]
-
- RandomDelta[] := With[{dir = Random[Real, range]}, {Cos[dir], Sin[dir]}]
-
- RandomWalk[n_Integer] :=
- Module[{points},
- points = NestList[ # + RandomDelta[]&, {0.0, 0.0}, n];
- Show[ Graphics[{Point[{0,0}], Line[points]}],
- Frame->True, FrameTicks->None, AspectRatio->1 ]
- ]
-
- End[]
-
- EndPackage[]
-