# Path: euler.py
# def euler_integrate(DS, t0, t1, dt, x0):
#     ts = linspace(t0, t1, (t1-t0)/dt)
#     xs = zeros(len(ts), float)
#     x = x0
#     for i, t in enumerate(ts):
#         xs[i] = x
#         x = euler_step(DS, t, x, dt)
#     return ts, xs


from PyDSTool import *
from euler import euler_integrate
# assign the RHS definitions for the ODE, the vardict dictionary,
# to the varspecs attribute of DSargs
DSargs.varspecs = vardict

# Create an object representing the implementation of the model.
# In PyDSTool, this is known as a Generator object, because
# it can numerically compute ("generate") trajectories using the VODE
# integration scheme.
DS = Generator.Vode_ODEsystem(DSargs)

# This shows how to change just these entries once the Generator has been created
DS.set(ics={'v': -75})

# A function that tests the outcome of a given value of parameter tau
def test_tau(tau):
    DS.set(pars={'tau': tau},
           algparams={'init_step': min(tau/2,0.5)})
    traj = DS.compute('test')
    pts = traj.sample()
    return pts

# A loop to test a distribution of values of tau
for tau in 40*exp(-linspace(1, 6, 6)):
    pts = test_tau(tau)
    plt.plot(pts['t'], pts['v'], '.-', label='tau=%.3f (VODE)' %tau)

# Find solutions using Euler integration
def test_tau_euler(tau, step, symb):
    DS.set(pars={'tau': tau})
    print "Testing Euler method with tau =", tau

# Path: euler.py
# def euler_integrate(DS, t0, t1, dt, x0):
#     ts = linspace(t0, t1, (t1-t0)/dt)
#     xs = zeros(len(ts), float)
#     x = x0
#     for i, t in enumerate(ts):
#         xs[i] = x
#         x = euler_step(DS, t, x, dt)
#     return ts, xs


# Path: linear_ODE.py
from PyDSTool import *
from euler import euler_integrate

# assign the RHS definitions for the ODE, the vardict dictionary,
# to the varspecs attribute of DSargs
DSargs.varspecs = vardict

# Create an object representing the implementation of the model.
# In PyDSTool, this is known as a Generator object, because
# it can numerically compute ("generate") trajectories using the VODE
# integration scheme.
DS = Generator.Vode_ODEsystem(DSargs)

# This shows how to change just these entries once the Generator has been created
DS.set(ics={'v': -75})

# A function that tests the outcome of a given value of parameter tau
def test_tau(tau):
    DS.set(pars={'tau': tau},
           algparams={'init_step': min(tau/2,0.5)})
    traj = DS.compute('test')
    pts = traj.sample()
    return pts

# A loop to test a distribution of values of tau
for tau in 40*exp(-linspace(1, 6, 6)):
    pts = test_tau(tau)
    plt.plot(pts['t'], pts['v'], '.-', label='tau=%.3f (VODE)' %tau)

# Find solutions using Euler integration
def test_tau_euler(tau, step, symb):
    DS.set(pars={'tau': tau})
    print "Testing Euler method with tau =", tau

    ts, vs = euler_integrate(DS, 0, 20, step, DS.initialconditions['v'])