## Re: [Speed-dreams-devel] Optimization of calculation of torque from rads

 Re: [Speed-dreams-devel] Optimization of calculation of torque from rads From: W.-D. Beelitz - 2010-06-21 12:06:58 ```Hello Christos, sorry but based on your proposal I would use: > 1. Assume we have r_1, ..., r_n rpm points with values T_1, ..., T_n. > 2. Let r be the last rpm value and [r_i, r_j] be the smallest interval containing r (i.e. so that j = i + 1) > 3. Let r' be the current rpm value. 4. If r' > r_j, do a binary search on the interval [r_j, r_n] else if r' < r_i do a binary search on the interval [r_1,r_i] else interpolate T' in [r_i, r_j] at r'. 5. Obtain a new interval [r'_i, r'_j]. And caused by the context I would expect that if r' > r_j the resulting interval will be [r_j, r_j+1] and for r' < r_i [r_i-1, r_i]. So for |r'- r| < eps we should look at previous/next interval if not the current interval matches. For |r'- r| > eps we should use the binary search as described above. Having no r we should use the binary search on the interval [r_1,r_n]. Regards Wolf-Dieter -----UrsprÃ¼ngliche Nachricht----- Von: Christos Dimitrakakis [mailto:olethros@...] Gesendet: 21 June 2010 09:31 An: speed-dreams-devel@... Betreff: Re: [Speed-dreams-devel] Optimization of calculation of torque from rads On 21/06/10 09:21, Christos Dimitrakakis wrote: > On 21/06/10 07:46, W.-D. Beelitz wrote: >> The value of rpms is changing "slowly" in most cases. PS2. So, the ideal way to implement this is as follows: 1. Assume we have r_1, ..., r_n rpm points on the spline, with values T_1, ..., T_n. 2. Let r be the last rpm value and [r_i, r_j] be the smallest interval containing r (i.e. so that j = i + 1) 3. Let r' be the current rpm value. 4. If r' > r, do binary search on the interval [r_i, r_n], else do binary search on the interval [r_1, r_j]. 5. Obtain a new interval [r'_i, r'_j]. As you can see, this reduces computation by a factor of 2. So, original complexity: O(n), binary search O(log n), and this O(log sqrt(n)). Again, I wouldn't do a linear search because once the number of points n increases, the amount of search increases with rate O(n). ---------------------------------------------------------------------------- -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Speed-dreams-devel mailing list Speed-dreams-devel@... https://lists.sourceforge.net/lists/listinfo/speed-dreams-devel ```