Thomas W-P wrote:
...
My way relies on the fact that if you plot power against distance with log scales you get a straight line. If you have two maximum effort pieces you can determine the gradient and intercept, and from that predict any other power for any other distance and from that get the time...
My way is very hard to code in javascript so I am open to offers for simpler ways.
Maybe I can help to simplify the code – if my bad English does not hinder the understanding.
Your code relies on the idea that ln(distance) vs ln(power) is a straight line. It can be shown that also ln(distance) vs ln(time) is a straight line which makes everything a lot easier.
A straight line means the following:
ln(P) = m * ln(d) + c , where P ist power and d is distance. m is the gradient and c the intercept.
As P equals v^3 * k we can write
ln(v^3 * k) = m * ln(d) +c
The rules for logarithms say this is
ln(k) + ln(v^3) = m * ln(d) + c
or
ln(v^3) = m * ln(d) + c - ln(k)
If we substitute c for (c - ln(k)) – where the two c's are not the same – we get
ln(v^3) = m * ln(d) + c
which ist again the formula for a straight line.
According the rules for logs this is equivalent to
3 * ln(v) = m * ln(d) + c
or
ln(v) = m/3 * ln(s) + c/3
We substitute again and get
ln(v) = m * ln(d) + c
Also a straight line.
As v equals d/t we can write
ln(d/t) = m * ln(d) + c
According the rules for logs this is equivalent to
ln(d) – ln(t) = m * ln(d) + c
–ln(t) = (m – 1) * ln(d) + c
ln(t) = (1 – m) * ln(d) – c
If we substitute m for (1 – m) and substitute c for (–c)
we again have the form of a
straight line like above:
ln(t) = m * ln(s) + c
This is equivalent to
ln(s) = (ln(t) - c) / m
So you have to calculate m and c from two points (ln(t1);ln(s1)) and (ln(t2);ln(s2)) like before but it is a lot easier and then you can easily find ln(t) from ln(s) and ln(s) from ln(t) without iteration. You don't need the power (Watts) at all. And then no cube or cuberoot is necessary any more.