I am trying to integrate function defined as f in the code using odeint from scipy. The function f takes theta, t, and K as arguments, which are defined below the function f. y is the result, for which I am getting error. The reason for error is theta which is 2 dimensional. I am not able to perform integration. Could somebody help me in this ?
import numpy as np
import random
from scipy.integrate import odeint
f
is function to be integrated
def f(theta, t, K):
global N
tau = 1.5
dtheta = np.zeros([T,N], float)
for i in range(N):
s = 0.
for j in range(i+1,N):
s = s + np.sin(theta[t-tau,j] - theta[t,i])
dtheta[t,i] = K*s
return dtheta
# Number of nodes
N = 10
# Constant
K = 1.0
# Number of time steps
T = 100
t = np.linspace(0, T, 100, endpoint=False)
theta = np.zeros([T,N], float)
Uniformly generates random number
for i in range(N):
theta[0,i] = random.uniform(-180, 180)
Integrate function f
using odeint
from scipy
y = odeint(f, theta, t, args=(K,))
print y
Write
y = odeint(f, theta.ravel(), t, args=(K,))
and
def f(theta, t, K):
global N
theta = theta.reshape(T, N)
...
return dtheta.ravel()
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.