view src/rlm/resistors.clj @ 0:78a630e650d2

initial import
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 00:57:08 -0700
parents
children
line wrap: on
line source
1 (ns rlm.resistors
2 (:use [clojure.contrib [accumulators :only [combine] ]])
3 (:use [incanter core stats charts]))
5 (def value 1)
7 (defn parrallel [r1 r2]
8 (/ 1 (+ ( / 1 r1) ( / 1 r2))))
10 (defn series [r1 r2]
11 (+ r1 r2))
13 (defn total-nums [num-resistors]
14 (if (= 1 num-resistors) #{value}
15 (combine
16 (apply hash-set (map (partial parrallel value) (total-nums (dec num-resistors))))
17 (apply hash-set (map (partial series value) (total-nums (dec num-resistors))))
18 (total-nums (dec num-resistors))
19 )))
21 (def total-nums (memoize total-nums))
23 (defn spectrum [num]
24 (apply sorted-set (map float (total-nums num))))
26 (defn oh-yeah []
27 (view (dynamic-scatter-plot [number (range 1 13 1)]
28 (let [vvv (apply vector (rlm.resistors/spectrum number))]
29 [(map identity vvv)
30 (repeat (count vvv) 0)])
31 :title "Resistor Combination Distribution")))