from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import math
from scipy.integrate import odeint
from scipy.fftpack import fft, ifft
def pend(y, t, a, b, ohm):
theta, omega, phi = y
dydt = [omega, -b*omega-np.sin(theta)-a*np.cos(phi), ohm]
return dydt
b = 1.0/2.0 #beta
ohm = 2.0/3.0 #capital Omega
period = 2.0*math.pi/ohm #driving period
t0 = 0.0 #initial time
t = np.linspace(t0,t0+period*10**3,10**3+1) #time for Poincare map
theta0 = 0.75
omega0 = 1.6
phi0 = 0.8
y0 = [theta0,omega0,phi0] #initial conditions
N = 100 #number of transient points to delete
a_array = np.linspace(0,1.15,50) #varying parameter of a values
for a in a_array:
sol = odeint(pend,y0,t,args=(a,b,ohm)) #numerical integration of differential equation
sol = sol[N:10**3-N] #removing transients
w = sol[:,1] #frequency
A = np.full(len(w),a) #array of a-values
plt.plot(A, w)
plt.draw()
I'm trying to construct a bifurcation diagram currently. In the system of equations we're using, a is the control parameter, which we're plotting for values between 0 and 1.15 on the x-axis vs. an array of values (called w) for a particular value of a. I'm not really sure how to plot things from within a for loop like this. I've heard that subplots are the best way to go, but I'm unfamiliar with implementation and could use some help. Thanks!
Unindenting the last command worked for me.
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import math
from scipy.integrate import odeint
from scipy.fftpack import fft, ifft
def pend(y, t, a, b, ohm):
theta, omega, phi = y
dydt = [omega, -b*omega-np.sin(theta)-a*np.cos(phi), ohm]
return dydt
b = 1.0/2.0 #beta
ohm = 2.0/3.0 #capital Omega
period = 2.0*math.pi/ohm #driving period
t0 = 0.0 #initial time
t = np.linspace(t0,t0+period*10**3,10**3+1) #time for Poincare map
theta0 = 0.75
omega0 = 1.6
phi0 = 0.8
y0 = [theta0,omega0,phi0] #initial conditions
N = 100 #number of transient points to delete
a_array = np.linspace(0,1.15,50) #varying parameter of a values
for a in a_array:
sol = odeint(pend,y0,t,args=(a,b,ohm)) #numerical integration of differential equation
sol = sol[N:10**3-N] #removing transients
w = sol[:,1] #frequency
A = np.full(len(w),a) #array of a-values
plt.plot(A, w)
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.