2016-05-14 1 views
0

Я относительно новым для Python и пытается использовать его, чтобы решить проблему IntegratorPython ODEINT проблемы с арг

x' = - L * x 

Где L ì лапласиан матрицы, то есть матрица представление графа. Это часть моего кода:

def integrate_cons(x, t, l): 
    xdot = -l*x 
    return xdot; 

t = np.linspace(0, 10, 101) 

#laplacian is a 3x3 matrix 
#initial_condition is a vector 
solution = odeint(integrate_cons, initial_conditions, t, args=(laplacian,)) 
print solution 

У меня возникли проблемы с передачей матрицы как аргумента в odeint. Как я могу решить?

ответ

0
import numpy as np 
from scipy.integrate import odeint 

def integrate_cons(x, t, l): 
    # unless you use np.matrix which I never do, you have to use np.dot 
    xdot = -np.dot(l,x) 
    return xdot; 

t = np.linspace(0, 10, 101) 
# just a random matrix 
l = np.random.rand(3,3) 
# initial conditions 
x0 = np.array([1,1,1]) 
#laplacian is a 3x3 matrix 
#initial_condition is a vector 
solution = odeint(integrate_cons, x0, t, args=(l,)) 
print(solution) 

Посмотрите на scipy cookbook для примеров.

+0

Это помогло мне, спасибо. Теперь у меня проблемы с построением решений. Я попытался с помощью 'plt.plot (t, solution [:, 0])', но я получаю ошибку. «Кортежные индексы должны быть целыми, а не кортежем». – oigna

+0

не может воспроизвести вашу ошибку – Moritz