[chronojump] In sprint 3 photocells iterations limited to 10000
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] In sprint 3 photocells iterations limited to 10000
- Date: Wed, 19 Apr 2017 09:25:08 +0000 (UTC)
commit 82e1e85b50743f4a072afa25500b3d175b5bf1c7
Author: Xavier Padullés <x padulles gmail com>
Date: Wed Apr 19 11:22:50 2017 +0200
In sprint 3 photocells iterations limited to 10000
r-scripts/sprintPhotocells.R | 27 ++++++++++++++++++++++++++-
r-scripts/sprintUtil.R | 23 -----------------------
2 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/r-scripts/sprintPhotocells.R b/r-scripts/sprintPhotocells.R
index 5befac4..7df1492 100644
--- a/r-scripts/sprintPhotocells.R
+++ b/r-scripts/sprintPhotocells.R
@@ -65,7 +65,7 @@ getSprintFromPhotocell <- function(positions, splitTimes, noise=0)
#if there's only three positions. Substituting x1 = x(t1), and x2 = x(t2) whe have an exact solution.
#2 variables (K and Vmax) and 2 equations.
if (length(positions) == 3){
- return(getSprintFrom2SplitTimes(x1 = positions[2], x2 = positions[3], t1 = splitTimes[2], t2
= splitTimes[3] ))
+ return(getSprintFrom2SplitTimes(positions[2], positions[3], splitTimes[2], splitTimes[3],
tolerance = 0.0001, initK = 1 ))
}
photocell = data.frame(time = splitTimes, position = positions)
@@ -80,6 +80,31 @@ getSprintFromPhotocell <- function(positions, splitTimes, noise=0)
return(list(K = K, Vmax = Vmax))
}
+#Given x(t) = Vmax*(t + (1/K)*exp(-K*t)) -Vmax - 1/K
+# x1 = x(t1) eq. (1)
+# x2 = x(t2) eq. (2)
+#Isolating Vmax from the first expressiona and sustituting in the second one we have:
+# x2*(t1 + exp(-K*t1)/K - 1/K) = x1*(t2 + exp(-K*t2)/K -1/K) eq. (3)
+#Passing all the terms of (3) at the left of the equation to have the form y(K) = 0
+#Using the iterative Newton's method of the tangent aproximation to find K
+#Derivative: y'(K) = (x2/x1)*(t1 - exp(-K*t1)*(K*t1 + 1)/K^2 + 1/K^2) + exp(-K*t2)*(K*t2 +1) - 1/K^2
+getSprintFrom2SplitTimes <- function(x1, x2, t1, t2, tolerance = 0.0001, initK = 1)
+{
+ #We have to find the K where y = 0.
+ K = initK
+ y = (x2/x1)*( t1 + exp(-K*t1)/K - 1/K) - t2 - exp(-K*t2)/K + 1/K
+ nIterations = 0
+ while ((abs(y) > tolerance) && (nIterations < 10000)){
+ nIterations = nIterations + 1
+ derivY = (x2/x1)*(t1 - exp(-K*t1)*(K*t1 + 1)/K^2 + 1/K^2) + exp(-K*t2)*(K*t2 +1) - 1/K^2
+ K = K - y / derivY
+ y = (x2/x1)*( t1 + exp(-K*t1)/K - 1/K) - t2 - exp(-K*t2)/K + 1/K
+ }
+ #Calculing Vmax substituting the K found in the eq. (1)
+ Vmax = x1/(t1 + exp(-K*t1)/K -1/K)
+ return(list(K = K, Vmax = Vmax))
+}
+
drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, title, plotFittedSpeed = T,
plotFittedAccel = T, plotFittedForce = T, plotFittedPower = T)
{
diff --git a/r-scripts/sprintUtil.R b/r-scripts/sprintUtil.R
index 59bd73d..b8aeeff 100644
--- a/r-scripts/sprintUtil.R
+++ b/r-scripts/sprintUtil.R
@@ -90,29 +90,6 @@ splitTime <- function(Vmax, K, position, tolerance = 0.001, initTime = 1)
return(t)
}
-#Given x(t) = Vmax*(t + (1/K)*exp(-K*t)) -Vmax - 1/K
-# x1 = x(t1) eq. (1)
-# x2 = x(t2) eq. (2)
-#Isolating Vmax from the first expressiona and sustituting in the second one we have:
-# x2*(t1 + exp(-K*t1)/K - 1/K) = x1*(t2 + exp(-K*t2)/K -1/K) eq. (3)
-#Passing all the terms of (3) at the left of the equation to have the form y(K) = 0
-#Using the iterative Newton's method of the tangent aproximation to find K
-#Derivative: y'(K) = (x2/x1)*(t1 - exp(-K*t1)*(K*t1 + 1)/K^2 + 1/K^2) + exp(-K*t2)*(K*t2 +1) - 1/K^2
-getSprintFrom2SplitTimes <- function(x1, x2, t1, t2, tolerance = 0.0001, initK = 1)
-{
- #We have to find the K where y = 0.
- K = initK
- y = (x2/x1)*( t1 + exp(-K*t1)/K - 1/K) - t2 - exp(-K*t2)/K + 1/K
- while (abs(y) > tolerance){
- derivY = (x2/x1)*(t1 - exp(-K*t1)*(K*t1 + 1)/K^2 + 1/K^2) + exp(-K*t2)*(K*t2 +1) - 1/K^2
- K = K - y / derivY
- y = (x2/x1)*( t1 + exp(-K*t1)/K - 1/K) - t2 - exp(-K*t2)/K + 1/K
- }
- #Calculing Vmax substituting the K found in the eq. (1)
- Vmax = x1/(t1 + exp(-K*t1)/K -1/K)
- return(list(K = K, Vmax = Vmax))
-}
-
prepareGraph <- function(os, pngFile, width, height)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]