求解杆的1-D热方程式在8次迭代后完全分解
我正在使用有限的差异技术,或者实际上只是Euler的方法,但具有部分导数。在“水浴”中有两个端的标记边界条件。它在最初的7次迭代中衰减良好,但是在第八次,热信号无处可寻。它必须来自热WRT位置的第二部分衍生物,但我不知道原因。
import numpy as np
from math import *
import matplotlib.pyplot as plt
# Solving the Heat Equation d(u)/d(t) = k * d^2(u)/d(x)^2
tot=100 #just a number of points
L=10 #length of rod
tf=10 #final time
k=3 #k for konstant
x=np.linspace(0,L,tot) #1-D position
t=np.linspace(0,tf,tot) #time
u=np.zeros((tot,tot)) #heat(x,t)
dx=L/tot
dt=tf/tot
for i in range(tot):
u[i,0]=6*sin(pi/L*x[i]) #heat at t=0 boundary. Just some function of x
for i in range(tot): #heat at x=0 and x=L edge boundaries
u[0,i]=0
u[tot-1,i]=0
for i in range(tot): #i=time
z=[] #z is just used for plotting
z.append(u[0,i])
for j in range(1,tot-1): #j=x-position
u_xx=(u[j+1,i]-2*u[j,i]+u[j-1,i])/(dx**2) #get u_xx at j,i
u_t=k*u_xx #solve eq for du/dt
u[j,i+1]=u_t*dt + u[j,i] #integrate du/dt
z.append(u[j,i])
z.append(u[tot-1,i])
plt.plot(z)
plt.show()
#print(u[50])#iteration 50
I am using the finite difference technique, or really just Euler's method but with a partial derivative. There are labeled boundary conditions with the 2 ends in a "water bath". It decays fine for the first 7 time iterations, but on the eighth, the heat signal gets a ton of noise out of nowhere. It must come from the second partial derivative of heat w.r.t. position, but I cannot figure out why.
import numpy as np
from math import *
import matplotlib.pyplot as plt
# Solving the Heat Equation d(u)/d(t) = k * d^2(u)/d(x)^2
tot=100 #just a number of points
L=10 #length of rod
tf=10 #final time
k=3 #k for konstant
x=np.linspace(0,L,tot) #1-D position
t=np.linspace(0,tf,tot) #time
u=np.zeros((tot,tot)) #heat(x,t)
dx=L/tot
dt=tf/tot
for i in range(tot):
u[i,0]=6*sin(pi/L*x[i]) #heat at t=0 boundary. Just some function of x
for i in range(tot): #heat at x=0 and x=L edge boundaries
u[0,i]=0
u[tot-1,i]=0
for i in range(tot): #i=time
z=[] #z is just used for plotting
z.append(u[0,i])
for j in range(1,tot-1): #j=x-position
u_xx=(u[j+1,i]-2*u[j,i]+u[j-1,i])/(dx**2) #get u_xx at j,i
u_t=k*u_xx #solve eq for du/dt
u[j,i+1]=u_t*dt + u[j,i] #integrate du/dt
z.append(u[j,i])
z.append(u[tot-1,i])
plt.plot(z)
plt.show()
#print(u[50])#iteration 50
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数值方案可能是或不可能是可持续性。不稳定意味着解决方案中的任何小误差(例如,舍入错误)会很快增加。您使用的计划是不稳定的。对于线性方程,可以通过(例如)谐波分析进行方案稳定性分析。该分析表明,如果2 k dt/dx/dx< 1,欧拉方案将是稳定的。
无条件稳定方案(曲柄 - 尼古尔森计划)的例子如下:
Numerical schemes may or may not be sustainability. Unstable means that any small error in the solution (e.g., rounding error) increases very quickly. The scheme you used is unstable. For linear equations, scheme stability analysis can be do with (for example) harmonic analysis. This analysis shows that the Euler scheme will be stable if 2kdt/dx/dx<1.
The example of unconditionally stable scheme (Crank–Nicolson scheme) is given below: