2016-09-28 28 views
0

我試圖解決的微分方程系統使用在賦SciPy的稀疏的解算器

X'=其中x斧(0)= F(X)

在Python,其中A確實是一個複雜的

稀疏矩陣。

現在,我一直在以下列方式使用scipy.integrate.complex_ode類來解決系統問題。

def to_solver_function(time,vector): 
    sendoff = np.dot(A, np.transpose(vector)) 
    return sendoff 

solver = complex_ode(to_solver_function) 
solver.set_initial_value(f(x),0) 

solution = [f(x)] 
for time in time_grid: 
    next = solver.integrate(time) 
    solution.append(next) 

這一直工作正常,但我需要「告訴求解器」我的矩陣是稀疏的。我想我應該使用

Asparse = sparse.lil_matrix(A) 

但我該如何改變我的求解器來處理這個問題?

回答

1

多大和稀疏是A

看起來A僅僅是一個常數這樣的功能:

def to_solver_function(time,vector): 
    sendoff = np.dot(A, np.transpose(vector)) 
    return sendoff 

vector 1D?然後np.transpose(vector)什麼都不做。

爲計算方便,你想

Asparse = sparse.csr_matrix(A) 

是否np.dot(Asparse, vector)工作? np.dot應該是稀疏的意識。如果不是,請嘗試Asparse*vector。這可能會產生一個密集的矩陣,因此您可能需要(Asparse*vector).A1來生成1d陣列。

但檢查時間。 Asparse需要非常大且非常稀疏才能在點積中執行比A更快的速度。