# cast42

Cast for two

## Friday, January 31, 2014

### Adding virtual power to TCX for the Tacx Blue Motion Cycling Trainer

I recently bought a cycle trainer for indoor training: Tacx Blue Motion T2600 for 185€ at fiets.be, a local cycling store. Using my Garmin 800, i could record my heartrate, cadence and speed while riding a workout. Since I have no power meter on my bike, I was barred from a feature that higher and more expensive trainers offer. But in the documentation of the trainer, I found a graph showing a linear relation between speed and power. So if I just could add this to the recorded file before submitting it to Strava, I would have trainer for less than 200€ with power measurement. This is the graph:

From that graph we can derive that riding at 60 km/h in position 5 (the middle blue line) a power of 500 Watt is developed. Hence power = speed / 60 * 500 = speed / 6 * 50 . Remark that speed must be in Km/h dimensions to obtain the power in Watt. There's even an interactive graph at website of Tacx. The Garmin 800 measures speed by counting the number of revolution of the wheel in a time unit and multiplying this by the circumference of the wheels. I converted the .fit file, I obtained from the Garmin device, in TCX (a XML file) using Garmin Training Center (Free software available for Windows and Mac). This file basically contains a list of trackpoints (1 trackpoint every second). One trackpoint looks like this:
        <Trackpoint>
<Time>2014-01-29T20:38:59Z</Time>
<AltitudeMeters>157.4000244</AltitudeMeters>
<DistanceMeters>14850.7099609</DistanceMeters>
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>139</Value>
</HeartRateBpm>
<Extensions>
<Speed>8.4530001</Speed>
</TPX>
</Extensions>
</Trackpoint>

At this time, the speed was 8.4530001 meter per second. To convert this to km/h, we have to divide by thousand and multiply by 3600 (the number of seconds in an hour). So speed_in_kmperh = speed /1000.0 * 60 *60 = 30.43080036 km/h. The power developed at that moment was : 30.43080036/6.0*50.0 = 253.590003 Watts. We convert to integer : 253 Watt. To add this to the TCX file, we add a line <Watts>253</Watts> as follows:
        <Trackpoint>
<Time>2014-01-29T20:38:59Z</Time>
<AltitudeMeters>157.4000244</AltitudeMeters>
<DistanceMeters>14850.7099609</DistanceMeters>
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>139</Value>
</HeartRateBpm>
<Extensions>
<Speed>8.4530001</Speed>
<Watts>253</Watts>
</TPX>
</Extensions>
</Trackpoint>

The next step was to automate the calculation of the power and adding it to the TCX file. I wrote the following Python script to do that:
prompt> python vpower.py > vpower_29-01-14\ 20-53-27.tcx

I uploaded the resulting TCX file to Strava and obtained this:
Of course, the power in this workout is based on the fact that I left the lever om my trainer on position 5 during the whole workout. If you change the position of the lever during the workout, this approach will give wrong results.

Is this approach of "virtual power" accurate ? Not as accurate as power meters on the bike but usable I would argue. The concept of "virtual power" is also supported by Trainer Road Software. Later, I found an interactive graph of the speed power relation for Tacx Blue Motion on the website of Tacx. From that graph, I could obtain more precise datapoints : at 60 km/h power is 407 Watt. So next time I use my script, I will use power = speed_in_kmperh / 60.0 * 407.0 as power formula.

## Wednesday, January 15, 2014

### Euler : great talk by William Dunham

Having a Google Chrome Cast at home increased my longform consumption on Youtube dramatically. For instance, I discovered this talk about the great mathematician Euler by William Dunham:

I learned from it that there's a simple polynomial discovered by Euler that generates 40 consecutive primes: $\forall n \in [0,40] : x^2+ x+ 41$ is a prime number.
You can check it by running following Python code:
You may wonder if there are other polynomials that generate primes. The article "Prime Generating Polynomials" claims that the polynomial $(x^5 - 133x^4 + 6729x^3 - 158379x^2 + 1720294x - 6823316)/4$ generates 57 consecutive primes for $x \in [0,56]$. Also the Wolfram article " Prime-Generating Polynomial indicates that polynomial as a winner. There are of course formula's to generate prime numbers but i think the Euler polynomial is the fastest.
The solution to Euler problem 27 is also interesting. A second degree polynomial generates 71 primes (but they are not consecutive). The polynomial $x^2 - 61x + 971$ generates 71 primes for $x \in [0,70]$. This is the longest solution when the absolute values of the coefficients are restricted to thousand. If we drop that restriction, an even stronger polynomial is found : $x^2 -79 x + 1601$ generates 80 primes. Remark that the generated primes are not unique. For example the numbers 1601, 41, 197, 797, 1373, 1523 are generated twice. From the 80 primes generated, 40 are unique. I think Euler would not have been impressed.