Post Reply 
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
{2 1 2} needs 2 + 2/3 seconds v = 15/8 m/s
{1 3 1} needs 2 + 1/2 seconds v = 2 m/s
{3 2} needs 2 seconds v = 5/2 m/s

These values appear to agree with mine:
(01-03-2019 04:44 PM)Thomas Klemm Wrote:  \(\begin{matrix}
5 \div \frac{10}{3} & = \frac{3}{2} & = 1.500\\
5 \div \frac{8}{3} & = \frac{15}{8} & = 1.875 \\
5 \div \frac{5}{2} & = 2 & = 2.000 \\
5 \div \frac{5}{2} & = 2 & = 2.000 \\
5 \div 2 & = \frac{5}{2} & = 2.500
\end{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))))
((1) (1/2 1/2) (1) (1/3 1/3 1/3) (1/2 1/2))

Flatten the result:
Code:
user=> (->> (for [n [1 2 1 3 2]] (repeat n (/ 1 n))) flatten)
(1 1/2 1/2 1 1/3 1/3 1/3 1/2 1/2)

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))
((1 1/2 1/2 1 1/3) (1/2 1/2 1 1/3 1/3) (1/2 1 1/3 1/3 1/3) (1 1/3 1/3 1/3 1/2) (1/3 1/3 1/3 1/2 1/2))

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))
(10/3 8/3 5/2 5/2 2N)

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)))
(3/2 15/8 2N 2N 5/2)

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))
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
dynamical list problem - peacecalc - 01-02-2019, 04:36 PM
RE: dynamical list problem - grsbanks - 01-02-2019, 06:08 PM
RE: dynamical list problem - BruceH - 01-02-2019, 06:47 PM
RE: dynamical list problem - peacecalc - 01-02-2019, 07:14 PM
RE: dynamical list problem - pier4r - 01-03-2019, 11:56 AM
RE: dynamical list problem - Albert Chan - 01-03-2019, 12:57 PM
RE: dynamical list problem - peacecalc - 01-03-2019, 02:11 PM
RE: dynamical list problem - Albert Chan - 01-03-2019, 03:13 PM
RE: dynamical list problem - peacecalc - 01-03-2019, 04:25 PM
RE: dynamical list problem - Thomas Klemm - 01-03-2019, 04:44 PM
RE: dynamical list problem - Albert Chan - 01-03-2019, 05:18 PM
RE: dynamical list problem - Thomas Klemm - 01-03-2019, 09:15 PM
RE: dynamical list problem - peacecalc - 01-04-2019, 08:51 AM
RE: dynamical list problem - BruceH - 01-04-2019, 01:21 PM
RE: dynamical list problem - Albert Chan - 01-04-2019, 02:34 PM
RE: dynamical list problem - Thomas Klemm - 01-04-2019 11:57 AM
RE: dynamical list problem - peacecalc - 01-05-2019, 09:48 AM
RE: dynamical list problem - Thomas Klemm - 01-05-2019, 12:54 PM
RE: dynamical list problem - DavidM - 01-05-2019, 05:13 PM
RE: dynamical list problem - Thomas Klemm - 01-05-2019, 07:45 PM
RE: dynamical list problem - John Keith - 01-07-2019, 04:55 PM
RE: dynamical list problem - Thomas Klemm - 01-07-2019, 08:29 PM



User(s) browsing this thread: 1 Guest(s)