from scipy.integrate import odeint
from pylab import *

#RHS vector of ODE
def f(y,t):
    return 1.2*y

#Analytic solution
def analytic(t,c):
    return c*exp(1.2*t)


#t for analytic solution
t=linspace(0.0, 2.0,20)

#initial condition
y0=linspace(0.5, 1.5, 5)
y=zeros([len(y0),20])

#calculate analytic solution
for i in range(len(y0)):
    y[i,:]=analytic(t,y0[i])

#time array 
ts=[0.0,0.5,1.0,1.5, 2.0]

#integrate ODE
ys=odeint(f,1.,ts)

#plot analytic solution
for i in range(len(y)):
    plot(t,y[i],'-')


#plot odeint solution
plot(ts,ys,'o-',label="odeint")

title("dy/dt=1.2y")
savefig("fig_ex_odeint2.jpg")
show()

bcde69ef7af58ced9746096bd46548cd829a722b
<mask token>


def f(y, t):
    return 1.2 * y


def analytic(t, c):
    return c * exp(1.2 * t)


<mask token>

<mask token>


def f(y, t):
    return 1.2 * y


def analytic(t, c):
    return c * exp(1.2 * t)


<mask token>
for i in range(len(y0)):
    y[i, :] = analytic(t, y0[i])
<mask token>
for i in range(len(y)):
    plot(t, y[i], '-')
plot(ts, ys, 'o-', label='odeint')
title('dy/dt=1.2y')
savefig('fig_ex_odeint2.jpg')
show()

<mask token>


def f(y, t):
    return 1.2 * y


def analytic(t, c):
    return c * exp(1.2 * t)


t = linspace(0.0, 2.0, 20)
y0 = linspace(0.5, 1.5, 5)
y = zeros([len(y0), 20])
for i in range(len(y0)):
    y[i, :] = analytic(t, y0[i])
ts = [0.0, 0.5, 1.0, 1.5, 2.0]
ys = odeint(f, 1.0, ts)
for i in range(len(y)):
    plot(t, y[i], '-')
plot(ts, ys, 'o-', label='odeint')
title('dy/dt=1.2y')
savefig('fig_ex_odeint2.jpg')
show()

from scipy.integrate import odeint
from pylab import *


def f(y, t):
    return 1.2 * y


def analytic(t, c):
    return c * exp(1.2 * t)


t = linspace(0.0, 2.0, 20)
y0 = linspace(0.5, 1.5, 5)
y = zeros([len(y0), 20])
for i in range(len(y0)):
    y[i, :] = analytic(t, y0[i])
ts = [0.0, 0.5, 1.0, 1.5, 2.0]
ys = odeint(f, 1.0, ts)
for i in range(len(y)):
    plot(t, y[i], '-')
plot(ts, ys, 'o-', label='odeint')
title('dy/dt=1.2y')
savefig('fig_ex_odeint2.jpg')
show()

from scipy.integrate import odeint
from pylab import *

#RHS vector of ODE
def f(y,t):
    return 1.2*y

#Analytic solution
def analytic(t,c):
    return c*exp(1.2*t)


#t for analytic solution
t=linspace(0.0, 2.0,20)

#initial condition
y0=linspace(0.5, 1.5, 5)
y=zeros([len(y0),20])

#calculate analytic solution
for i in range(len(y0)):
    y[i,:]=analytic(t,y0[i])

#time array 
ts=[0.0,0.5,1.0,1.5, 2.0]

#integrate ODE
ys=odeint(f,1.,ts)

#plot analytic solution
for i in range(len(y)):
    plot(t,y[i],'-')


#plot odeint solution
plot(ts,ys,'o-',label="odeint")

title("dy/dt=1.2y")
savefig("fig_ex_odeint2.jpg")
show()
