Beispiel #1
0
fig = figure(figsize=(12, 5))
ax1 = fig.add_subplot(121)
ax1.plot(ta, sol[0], '-', lw=2.0, label=r'$u$')
ax1.plot(ta, sol[1], '-', lw=2.0, label=r'$v$')

ax1.set_xlabel(r'$u,v$')
ax1.set_ylabel(r'$f(u),f(v)$')
ax1.set_title('Solution')
leg = ax1.legend(loc='right center')
leg.get_frame().set_alpha(0.5)
ax1.grid()

# Plot the results
ax2 = fig.add_subplot(122)
xmin = sol[0].min()
xmax = sol[0].max()
ymin = sol[1].min()
ymax = sol[1].max()
ax2.set_xlim([xmin, xmax])
ax2.set_ylim([ymin, ymax])

# plot the direction field for the problem
dirField_2(dudt, dvdt, ax2, (alpha, beta), (gamma, delta))
ax2.plot(sol[0], sol[1])

ax2.set_title(r'$(u,v)$ phase plane')
ax2.set_xlabel(r'$u$')
ax2.set_ylabel(r'$v$')
tight_layout()
show()
Beispiel #2
0
dx = 0.1

x1 = arange(x1min, x1max, dx)
x2 = arange(x2min, x2max, dx)

# time range to plot the solution curves :
t = arange(-20, 10, 0.01)

# set up the plot window :
fig = figure()
ax = fig.add_subplot(111)
ax.set_ylim(x2min, x2max)
ax.set_xlim(x1min, x1max)

# plot the direction field for the problem :
dirField_2(f1, f2, ax)

# coefficient choices are made log to plot better :
c = [.5, 1, 2, 3]

# formation of solution matrix X :
x11 = exp(t / 2) * 5 * cos(3 / 2. * t)
x12 = exp(t / 2) * 5 * sin(3 / 2. * t)
x21 = exp(t / 2) * 3 * (cos(3 / 2. * t) + sin(3 / 2. * t))
x22 = exp(t / 2) * 3 * (-cos(3 / 2. * t) + sin(3 / 2. * t))
x = array([[x11, x12], [x21, x22]])


def plot_solutions(cvec, x):
    '''
  plot the solutions to the matrix x for initial conditions c.
Beispiel #3
0
ax1 = fig.add_subplot(121)
ax1.plot(ta, sol[0], "-", lw=2.0, label=r"$u$")
ax1.plot(ta, sol[1], "-", lw=2.0, label=r"$v$")

ax1.set_xlabel(r"$u,v$")
ax1.set_ylabel(r"$f(u),f(v)$")
ax1.set_title("Solution")
leg = ax1.legend(loc="right center")
leg.get_frame().set_alpha(0.5)
ax1.grid()


# Plot the results
ax2 = fig.add_subplot(122)
xmin = sol[0].min()
xmax = sol[0].max()
ymin = sol[1].min()
ymax = sol[1].max()
ax2.set_xlim([xmin, xmax])
ax2.set_ylim([ymin, ymax])

# plot the direction field for the problem
dirField_2(dudt, dvdt, ax2, (alpha, beta), (gamma, delta))
ax2.plot(sol[0], sol[1])

ax2.set_title(r"$(u,v)$ phase plane")
ax2.set_xlabel(r"$u$")
ax2.set_ylabel(r"$v$")
tight_layout()
show()
Beispiel #4
0
dx    = 0.1

x1 = arange(x1min, x1max, dx)
x2 = arange(x2min, x2max, dx)

# time range to plot the solution curves :
t = arange(-20, 10, 0.01)

# set up the plot window :
fig = figure()
ax = fig.add_subplot(111) 
ax.set_ylim(x2min, x2max)
ax.set_xlim(x1min, x1max)

# plot the direction field for the problem :
dirField_2(f1, f2, ax)

# coefficient choices are made log to plot better :
c = [.5, 1, 2, 3]

# formation of solution matrix X :
x11 = exp(t/2)*5*cos(3/2.*t)
x12 = exp(t/2)*5*sin(3/2.*t)
x21 = exp(t/2)*3*(cos(3/2.*t) + sin(3/2.*t))
x22 = exp(t/2)*3*(-cos(3/2.*t) + sin(3/2.*t))
x = array([[x11, x12], [x21, x22]])

def plot_solutions(cvec, x):
  '''
  plot the solutions to the matrix x for initial conditions c.
  '''
Beispiel #5
0
  gamma = params[1]
  dSdt  = -alpha*I*S + gamma*(N - S - I)
  return array(dSdt)

def dIdt(S, I, params):
  """
  INPUT:
    S - population of susceptible
    I - population of infected.
  OUTPUT:
    dI/dt - time derivative of infected as a function of S and I.
  """
  alpha = params[0]
  beta  = params[1]
  dIdt  = alpha*I*S - beta*I
  return array(dIdt)

dirField_2(dSdt, dIdt, ax2, S_params, I_params)
ax2.plot(sol[0], sol[1])

ax2.set_title(r'$(S,I)$ phase plane')
ax2.set_xlabel(r'$S$')
ax2.set_ylabel(r'$I$')
tight_layout()
savefig('prb4b.png', dpi=300)
show()