- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用复杂到复杂的 IDFT 来求解一维热方程。问题是单个时间步长后的输出似乎不正确。我在下面包含了一个简单的例子来说明这个问题。
我初始化温度状态如下:
频域中的初始模式为:k[ 0] = 12.5 + 0i
k[ 1] = 12.5 + 0i
k[ 2] = 12.5 + 0i
k[ 3] = 12.5 + 0i
k[ 4] = 12.5 + 0i
k[-3] = 12.5 + 0i
k[-2] = 12.5 + 0i
k[-1] = 12.5 + 0i
然后我将频域的状态推进到 t=0.02
使用标准的一维热方程:
double alpha = 0.2; // Thermal conductivity constant
double timestep = 0.02;
for (int i = 0; i < N; i++) {
int k = (i <= N / 2) ? i : i - N;
F[i][REAL] *= exp(-alpha * k * k * timestep); // Decay the real part
F[i][IMAG] *= exp(-alpha * k * k * timestep); // Decay the imaginary part
}
t=0.02
处的频率模式变得:
k[ 0] = 12.5 + 0i
k[ 1] = 12.45 + 0i
k[ 2] = 12.3 + 0i
k[ 3] = 12.06 + 0i
k[ 4] = 11.73 + 0i
k[-3] = 12.06 + 0i
k[-2] = 12.3 + 0i
k[-1] = 12.45 + 0i
执行IDFT获得
t=0.02
处的温域状态后我得到:
double alpha = 0.2; // Thermal conductivity constant
double timestep = 0.02; // Physical heat equation timestep
int N = 8; // Number of data points
fftw_complex* T = (fftw_complex*)fftw_alloc_complex(N); // Temperature domain
fftw_complex* F = (fftw_complex*)fftw_alloc_complex(N); // Frequency domain
fftw_plan plan = fftw_plan_dft_1d(N, F, T, FFTW_BACKWARD, FFTW_MEASURE); // IDFT from frequency to temperature domain
// Initialize all frequency modes such that there is a peak of 100 at x=0 in the temperature domain
// All other other points in the temperature domain are 0
for (int i = 0; i < N; i++) {
F[i][REAL] = 100.0 / N;
F[i][IMAG] = 0.0;
}
// Perform the IDFT to obtain the initial state in the temperature domain
fftw_execute(plan);
printTime1d(T, N);
printFrequencies1d(F, N);
// Perform a single timestep of the heat equation to obtain the frequency domain state at t=0.02
for (int i = 0; i < N; i++) {
int k = (i <= N / 2) ? i : i - N;
F[i][REAL] *= exp(-alpha * k * k * timestep); // Decay the real part
F[i][IMAG] *= exp(-alpha * k * k * timestep); // Decay the imaginary part
}
// Perform the IDFT to obtain the temperature domain state at t=0.02
fftw_execute(plan);
printTime1d(T, N);
printFrequencies1d(F, N);
printTime(...)
的定义和
printFrequencies(...)
是:
void printTime1d(fftw_complex* data, int N) {
int rounding_factor = pow(10, 2);
for (int i = 0; i < N; i++) {
std::cout << std::setw(8) << round(data[i][REAL] * rounding_factor) / rounding_factor;
}
std::cout << std::endl;
}
void printFrequencies1d(fftw_complex* data, int N) {
int rounding_factor = pow(10, 2);
for (int i = 0; i < N; i++) {
int k = (i <= N / 2) ? i : i - N;
double R = round(data[i][REAL] * rounding_factor) / rounding_factor;
double I = round(data[i][IMAG] * rounding_factor) / rounding_factor;
std::cout << "k[" << std::setw(2) << k << "]: " << std::setw(2) << R << ((I < 0) ? " - " : " + ") << std::setw(1) << abs(I) << "i" << std::endl;
}
std::cout << std::endl;
}
也许值得一提的是,我还使用复杂到真实的 IDFT(使用 fftw 的
fftw_plan_dft_c2r_1d()
)进行了这个实验,它给出了完全相同的结果。
最佳答案
您的问题是您没有解决所需的频率,而是在乘以衰减系数后得到函数的以下傅立叶图像:
上面的结果与你应该得到的结果相差太远了——一个高斯——至少是这样的(使用 80 个点而不是 8 个):
请注意上面第一个图表中的振幅是如何甚至没有机会接近零,而是撞到奈奎斯特频率。很明显,您会得到类似于吉布斯现象的伪像:这是傅立叶部分和的常见行为。
80 点数据版本的傅里叶逆变换则如下:
这个结果仍然有负分量(因为我们使用了有限数量的谐波),但它们的幅度比你只用 8 个谐波得到的要小得多。
请注意,这确实意味着,如果您增加感兴趣的时间值,则可以减少考虑的谐波数量。起初这可能是出乎意料的,但这仅仅是因为高次谐波比低次谐波衰减得快得多,而且它们永远不会增加。
关于c++ - 使用 DFT 的一维热方程产生不正确的结果 (FFTW),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64155448/
我想要类似于以下伪代码的东西: while input is not None and timer = 5: print "took too long" else: print inp
如何将 MainEngine Observable 转换为 Cold?来自这个例子: public IObservable MainEngine { get
自从手表被发明以来,表盘的方圆之争就始终没有停下来过,在漫长的岁月中,无论是方形还是圆形表盘,人们都为其寻找到足够多的设计元素,让其肆意成长,这种生机与活力后来也延续到了智能手表上,在2014年,这
我正在学习 CUDA,试图解决一些标准问题。例如,我正在使用以下代码求解二维扩散方程。但我的结果与标准结果不同,我无法弄清楚。 //kernel definition __global__ void
我的 Web 应用程序使用 native dll 来实现其部分功能(其位置在 PATH 中提供)。一切正常,直到我对 WAR 进行更改并且 JBoss 热部署此 WAR。此时dll已经找不到了,需要手
我看到这个问题here 。这是关于实现每个发出的项目的延迟。这是根据accepted answer如何实现的: Observable.zip(Observable.range(1, 5) .g
我最近一直在进行冷迁移...这意味着我无法在进行迁移时从应用程序级别读取/写入数据库(维护页面)。 这样就不会因为更改结构而发生错误,而且如果负载很大,我也不希望 mysql 在迁移过程中崩溃。 我的
我是一名优秀的程序员,十分优秀!