*** A simple first order ode evaluated at specific points
:PROPERTIES:
:categories: ODE
:date: 2013/02/27 14:30:23
:updated: 2013/02/27 14:30:23
:END:
[[http://matlab.cheme.cmu.edu/2011/08/05/a-simple-first-order-ode-evaluated-at-specific-points/][Matlab post]]
We have integrated an ODE over a specific time span. Sometimes it is desirable to get the solution at specific points, e.g. at t = [0 0.2 0.4 0.8]; This could be desirable to compare with experimental measurements at those time points. This example demonstrates how to do that.
$$\frac{dy}{dt} = y(t)$$
The initial condition is y(0) = 1.
#+BEGIN_SRC python
from scipy.integrate import odeint
y0 = 1
tspan = [0, 0.2, 0.4, 0.8]
def dydt(y, t):
return y
Y = odeint(dydt, y0, tspan)
print Y[:,0]
#+END_SRC
#+RESULTS:
: [ 1. 1.22140275 1.49182469 2.22554103]