2016-12-12 4 views
1
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() 

현재 분기 다이어그램을 구성하려고합니다. 우리가 사용하는 방정식 시스템에서, a는 제어 매개 변수이며, x의 0과 1.15 사이의 값과 a의 특정 값에 대한 값의 배열 (w라고 함)을 나타냅니다. 나는 이렇게 for 루프 내에서 물건을 그리는 법을 정말로 모르겠다. 서브 플로트가 가장 좋은 방법이라고 들었지만 구현에 익숙하지 않아 도움이 될 수 있습니다. 감사!동일한 그래프에 여러 개의 하위 그림 그리기

+0

지금 당신의 코드를 실행합니다. 시간이 좀 걸릴. 그 동안 보통 plt.draw() 또는 plt.show()를 루프 외부로 이동합니다. –

답변

0

마지막 명령을 언인 드링하면 나를 위해 일했습니다.

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() 

enter image description here

+0

신속한 답변을 보내 주셔서 감사합니다. 나는 또한이 음모를 보았지만 거의 즉시 폐기했다. 1.05에서 1.15 사이의 값을 나타내는 것으로 보였으므로 옳지 않다. – infinitylord

+0

이게 당신이 찾고있는 것입니까? –

+0

a 배열의 특정 값에 대해 w 배열을 생성하는 경우, a의 각 값에 대해 동일한 그래프에 결과를 플로팅 한 다음 예를 들어 이것이 내가 찾는 값입니다 – infinitylord