Paste number 28807: 2d random walk

Paste number 28807: 2d random walk
Pasted by: Chiao
When:12 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+M87
Channel:None
Paste contents:
Raw Source | XML | Display As
(asdf:operate 'asdf:load-op 'rsm-memo)

(defparameter *a* (/ (- (sqrt 5) 1) 2))
;(defparameter *a* 0.99)
(defparameter *Nsteps* 100)
(defparameter *Ndots* (expt 10 5))

(rsm.memo:defmemo n2s (n)
  (expt *a* (+ n 1)))

(defun scatter (point n)
  (let* ((s (n2s n))
         (grid (list (list    s     s)
                     (list    s  (- s))
                     (list (- s)    s)
                     (list (- s) (- s)))))
    (mapcar #'+ point
            (elt grid (random 4)))))

(progn
  (defparameter *bins* '())
  (dotimes (iter *Ndots*)
    (push '(0 0) *bins*))
  (dotimes (iter *Nsteps*)
    (setf *bins*
          (mapcar #'(lambda (pt) (scatter pt iter))
                  *bins*))))

(with-open-file (stream "plot" :direction :output :if-exists :supersede)
  (dolist (pt *bins*)
    (format stream "~15f ~15f ~%" (elt pt 0) (elt pt 1))))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.