dynamical list problem
|
01-04-2019, 11:57 AM
Post: #14
|
|||
|
|||
RE: dynamical list problem
(01-04-2019 08:51 AM)peacecalc Wrote: {1 2 1 1} needs 3 + 1/3 seconds v = 3/2 m/s These values appear to agree with mine: (01-03-2019 04:44 PM)Thomas Klemm Wrote: \(\begin{matrix} Not sure if that helps but here's some Clojure code: Create a list of lists where each list contains n times \(\frac{1}{n}\): Code: user=> (->> (for [n [1 2 1 3 2]] (repeat n (/ 1 n)))) Flatten the result: Code: user=> (->> (for [n [1 2 1 3 2]] (repeat n (/ 1 n))) flatten) Move a window of length 5 with step 1 over the list: Code: user=> (->> (for [n [1 2 1 3 2]] (repeat n (/ 1 n))) flatten (partition 5 1)) Sum the elements of each list: Code: user=> (->> (for [n [1 2 1 3 2]] (repeat n (/ 1 n))) flatten (partition 5 1) (map sum)) Divide 5 by each of the results: Code: user=> (->> (for [n [1 2 1 3 2]] (repeat n (/ 1 n))) flatten (partition 5 1) (map sum) (map (partial / 5))) The average speed isn't calculated at equal time intervals. But this makes the calculation much easier. HTH Thomas PS: I've used the following definition of sum: Code: (defn sum [xs] (reduce + xs)) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)