summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2011-11-01 03:27:08 -0500
committerJoe Anderson <jandew+dev@gmail.com>2011-11-01 03:27:08 -0500
commit4177a8043f6172c7c40aab550a29039ce79f8439 (patch)
tree1aa1b21203c9262dc6a422b34f31f8a5027bb20f
parentdfacde4c4a6886582d0f64035d3c2a0700766a49 (diff)
downloadtoss-4177a8043f6172c7c40aab550a29039ce79f8439.tar.gz
toss-4177a8043f6172c7c40aab550a29039ce79f8439.zip
solid func, needs testing
-rw-r--r--throw.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/throw.py b/throw.py
index e36b151..b144eaa 100644
--- a/throw.py
+++ b/throw.py
@@ -143,20 +143,26 @@ def interpret(soln, max_tension):
return phi, phi1, v_tan, tension, moment, momentum, max_arg
-def solver(func, init_vars, timespace=(0,600,10**5), max_tension=max_tension):
+def solver(func, init_vars, timespace=(0,600,10**5), max_tension=max_tension,
+ returns=['time', 'variables', 'slices', 'maxes']):
for n in itertools.count(1):
time, soln = solve_fun(func, init_vars, timespace)
- try: phi, phi1, v_tan, tension, moment, momentum, max_arg = \
- interpret(soln, max_tension)
+ try: variables, max_arg = interpret(soln, max_tension)
except TimespaceTooSmall:
timespace = map(lambda x: x*.2*1.5**n, timespace)
continue
break
- phi, phi1, v_tan, tension, moment, momentum, time = \
- map(lambda x: numpy.ndarray.__getslice__(x, 0, max_arg+1),
- [phi, phi1, v_tan, tension, moment, momentum, time])
+ getslice = lambda x: numpy.ndarray.__getslice__(x, 0, max_arg+1)
+ getmax = lambda x: numpy.ndarray.__getitem__( x, max_arg)
+ slices = map(getslice, (time,) + variables)
+ maxes = map(getmax, (time,) + variables)
+
+ out = []
+ for item in returns: out.append(vars()[item])
+
+ return tuple(out)
def plot(time, soln, graphs=['all'], i=7):
phi, phi1, v_tan, tension, moment, momentum, max_arg = \
@@ -253,6 +259,10 @@ def opt_fun(guesses, f, func, init_vars):
map(lambda x: numpy.ndarray.__getslice__(x, 0, max_arg+1),
[phi, phi1, v_tan, tension, moment, momentum, time])
+ (time, soln,
+ (phi, phi1, v_tan, tension, moment, momentum, max_arg),
+ (
+
# Parameter values.
f.write("%s, " % r_roll)
f.write("%s, " % length)