我必須解決歐拉伯努利差動梁方程是:差分Python的有限差分法方程
u’’’’(x) = f(x) ;
(x是一個射束軸線的點的座標)
和邊界條件:
u(0)=0, u’(0)=0, u’’(1)=0, u’’’(1)=a
我研究的數字有限差理論表達該系列推導爲:
U’k = (1/2*h)(Uk+1 - Uk-1)
U’’k = (1/h2)(Uk+1 - 2 Uk + Uk-1)
U’’’k = (1/2h3)(Uk+2 - 2 Uk+1 + 2 Uk-1 + Uk-2)
U’’’’k = (1/h4)(Uk+2 - 4 Uk+1 + 6 Uk - 4 Uk-1 + Uk-2)
(k+1
,k+2
,等等等等都標)
,我發現了一個腳本,它表達爲如下:
import numpy as np
from scipy.linalg import solveh_banded
import matplotlib.pyplot as plt
def beam4(n,ffun,a):
x = np.linspace(0,1,n+1)
h = 1.0/n
stencil = np.array((1,-4,6))
B = np.outer(stencil,np.ones(n))
B[1,-1] = -2; B[2,0] = 7; B[2,-1] = 1; B[2,-2] = 5
f = ffun(x)
f *= h** 4; f[-1] *= 0.5; f[-1] -= a*h**3
u = np.zeros(n+1)
u[1:] = solveh_banded(B,f[1:],lower=False)
return x,u
但我不明白爲什麼係數矩陣建立這種方式:
stencil = np.array((1,-4,6))
B = np.outer(stencil,np.ones(n))
B[1,-1] = -2; B[2,0] = 7; B[2,-1] = 1; B[2,-2] = 5
f = ffun(x)
f *= h**4; f[-1] *= 0.5; f[-1] -= a*h**3 "
在此先感謝!!!!
你可以縮進您的代碼,以便它是可讀嗎? – khelwood
你知道如何用手解決這個方程嗎?如果沒有,我會建議先做這件事,然後試着用numpy來解決它。 – cpburnz
'sympy'會更適合嗎? http://sympy.org/en/index.html – atomh33ls