summaryrefslogtreecommitdiff
path: root/diffeq.py
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2011-11-13 14:39:47 -0600
committerJoe Anderson <jandew+dev@gmail.com>2011-11-13 14:39:47 -0600
commit5a2a5441bae50c7859b26dfc4c1550f8fb05cbf1 (patch)
treeb554f1f646ae063635eaee60d77db6b610811641 /diffeq.py
parentb756b1a28ba6686a0ed1fb9eeb366dee4b24e6dc (diff)
downloadtoss-5a2a5441bae50c7859b26dfc4c1550f8fb05cbf1.tar.gz
toss-5a2a5441bae50c7859b26dfc4c1550f8fb05cbf1.zip
forgot about this stash
Diffstat (limited to 'diffeq.py')
-rw-r--r--diffeq.py53
1 files changed, 43 insertions, 10 deletions
diff --git a/diffeq.py b/diffeq.py
index 1ecc705..05d42b6 100644
--- a/diffeq.py
+++ b/diffeq.py
@@ -85,22 +85,55 @@ class DiffEq(object):
"""Usage is as follows.
def method(self, var0=None, var1=None, ...):
- self.check_in(vars())
+ self.check_in(locals())
return do_stuff_with_vars()
"""
- for key, var in variables.items():
- if var == None:
+ for key, value in variables.items():
+ if value == None:
variables[key] = getattr(self, key)
- def solve_fun(self, func=None, init_vars=None, timespace=None):
- """wrapper for odeint"""
- check_in(vars())
- time0 = current_time()
+ def solve_diff_eq(self, diff_eq=None, init_vars=None, timespace=None):
+ """wrapper for odeint and self.diff_eq"""
+ self.check_in(locals())
+ time0 = self.time()
time = numpy.linspace(*timespace)
- soln = odeint(func, init_vars, time)
- print " :: took %s seconds" % (current_time() - time0)
+ soln = odeint(diff_eq, init_vars, time)
+ print " :: took %s seconds" % (self.time() - time0)
return time, soln
#in optimize(): vars().update(self.opt_vars)
-
+ def opt_fun(guesses, f, func, init_vars):
+ """Optimize the free variables for the diff eq."""
+ global r0, r_roll, length, m, Mass
+ r0, r_roll, length, m, Mass = guesses
+
+ time, soln = solve_fun(func, init_vars)
+
+ phi, phi1, v_tan, tension, moment, momentum, max_arg = \
+ interpret(soln)
+ 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])
+
+ time, (phi, phi1, v_tan, tension, moment, momentum, max_arg) = \
+ solver(func, init_vars, returns=['time', 'slices'])
+
+ # Parameter values.
+ f.write("%s, " % r_roll)
+ f.write("%s, " % length)
+ f.write("%s, " % r0)
+ f.write("%s, " % m)
+ f.write("%s, " % Mass)
+
+ # Values at the max velocity point.
+ f.write("%s, " % phi[-1])
+ f.write("%s, " % phi1[-1])
+ f.write("%s, " % tension[-1])
+ f.write("%s\n" % v_tan[-1])
+
+ time, soln = self.solve_func(
+
+ self.interpret()
+
+ return self.optimize_value()