计算SciPy中的傅里叶级数

时间:2017-09-01 14:19:03

标签: python numpy math scipy fft

带绝缘头的金属棒的热传输的一般解决方案是 enter image description here

我尝试计算给定时间的梯度,对于典型情况,初始温差为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)

但结果不是预期的结果 enter image description here

代码可能有什么问题?

1 个答案:

答案 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)

图表:

After 30 minutes one end will have temp=35 and the other end temp=65