我尝试计算给定时间的梯度,对于典型情况,初始温差为100
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,3,100)
L = 3
n_max = 20
def bn(n):
n = int(n)
if (n%2 != 0):
return 400/(np.pi**2*n**2)
else:
return 0
def wn(n):
global L
wn = (np.pi*n)/L
return wn
def fourierSeries(n_max,x,t):
a0 = 100/2
partialSums = a0
for n in range(1,n_max):
partialSums = partialSums + bn(n)*np.exp(-.00001*wn(n)**2*t)*np.cos(wn(n)*x)
return partialSums
u = []
for i in x:
u.append(fourierSeries(n_max,i,1))
plt.plot(x,u)
代码可能有什么问题?
答案 0 :(得分:2)
我相信你错过了杆的温度功能:
f(x)= T + 100 / L * x
使用它,并计算积分将完成这项工作。
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,3,100)
L = 3
n_max = 20
def bn(n):
b=200/n**2/np.pi**2*(np.cos(n*np.pi)-1)
return b
def wn(n):
wn = (np.pi*n)/L
return wn
def fourierSeries(n_max,x,t):
a0 = 100/2
partialSums = a0
for n in range(1,n_max):
partialSums = partialSums + bn(n)*np.exp(-.0005*wn(n)**2*t)*np.cos(wn(n)*x)
return partialSums
u = []
hour = 3600
for i in x:
u.append(fourierSeries(n_max,i,2*hour))
plt.plot(x,u)
图表: