[pstricks] Simulated random walks and Brownian motions
Herbert Voss
Herbert.Voss at alumni.TU-Berlin.DE
Fri Mar 14 09:08:28 CET 2003
John Harris schrieb:
>
> I am relatively new to PSTricks and would greatly appreciate some help
> trying to draw simulated random walks and Brownian motions. Presumably
> if I could do a random walk then scaling down the step size would
> produce a passable Brownian motion but I have not been able to get
> anything to work so far.
>
> Any hints anyone has would be great thanks.
I need it some time ago to show a kind of chaotic
behaviour and I did it in this way. The point could
only move one pixel left/right/up/down
Herbert
\documentclass{article}
\usepackage{pst-plot}
\makeatletter
\def\pstRandomWalk{\@ifnextchar[{\pst at RandomWalk}{\pst at RandomWalk[]}}
% #1 options which are passed to pstricks
% #2,#3 the starting point
% #4 the number of points
\def\pst at RandomWalk[#1](#2,#3)#4{%
\psset{#1}
\doRandomWalk(#2,#3){#4}
}
\def\doRandomWalk{%
\def\pst at par{}
\pst at object{psRandomWalk}%
}
\def\psRandomWalk at i(#1,#2)#3{%
\pst at killglue
\begingroup
\use at par
\@nameuse{beginplot@\psplotstyle}%
\addto at pscode{%
\psplot at init
/plotPoints #3 def
/x #1 def
/y #2 def
/xyWalk {
/xRandom rand 3 mod 1 sub def
/yRandom rand 3 mod 1 sub def
/x x xRandom add def
/y y yRandom add def
x y} def
}%
\gdef\psplot at init{}%
\@nameuse{testqp@\psplotstyle}%
\psRandomWalk at ii
\endgroup
\ignorespaces%
}
\def\psRandomWalk at ii{%
\addto at pscode{%
xyWalk \@nameuse{beginqp@\psplotstyle}
xyWalk moveto
plotPoints {
xyWalk \@nameuse{doqp@\psplotstyle}
} repeat
xyWalk \@nameuse{doqp@\psplotstyle}
}
\@nameuse{endqp@\psplotstyle}%
}
\makeatother
\begin{document}
\begin{pspicture}(-3,-3)(3,3)
\psframe(-3,-3)(3,3)
\pstRandomWalk[plotstyle=line, linewidth=0.5pt](0,0){5000}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list