• (n-sphere n r)
Return a uniform distribution of n-dimensional vectors inside an
n-sphere of radius r.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/probabilities/monte_carlo.clj:228 top

(with-monad state-m
  (defn n-sphere
    "Return a uniform distribution of n-dimensional vectors inside an
     n-sphere of radius r."
    [n r]
    (let [box-dist    (sample n (interval (- r) r))
	  sq          #(* % %)
	  r-sq        (sq r)
	  vec-sq      #(apply + (map sq %))
	  sphere-dist (reject #(> (vec-sq %) r-sq) box-dist)
	  as-vectors  (m-lift 1 vec)]
      (as-vectors sphere-dist))))
Vars in clojure.contrib.probabilities.monte-carlo/n-sphere: defn let
Used in 0 other vars

Comments top

No comments for n-sphere. Log in to add a comment.