From 92bd43e33e79a7d682267d3f6054e8b1dd9d00db Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 18 Apr 2025 22:09:32 -0300 Subject: Fixed bug and got integrator working --- fourier.cpp | 2 +- log-fourier_integrator.cpp | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fourier.cpp b/fourier.cpp index bb1c92f..15cad52 100644 --- a/fourier.cpp +++ b/fourier.cpp @@ -169,7 +169,7 @@ std::vector LogarithmicFourierTransform::fourier(const std::vector Cnew = fft.inverse(Ctnew); @@ -124,12 +125,28 @@ int main(int argc, char* argv[]) { // std::cerr << ΔC << std::endl; } - std::cerr << β << " " << μ << " " << Ct[0].real() << std::endl; + /* Integrate the energy using Simpson's rule */ + Real E = 0; + for (unsigned i = 0; i < N/2-1; i++) { + Real h₂ᵢ = fft.t(2*i+1) - fft.t(2*i); + Real h₂ᵢ₊₁ = fft.t(2*i+2) - fft.t(2*i+1); + Real f₂ᵢ = R[2*i] * df(λ, p, s, C[2*i]); + Real f₂ᵢ₊₁ = R[2*i+1] * df(λ, p, s, C[2*i+1]); + Real f₂ᵢ₊₂ = R[2*i+2] * df(λ, p, s, C[2*i+2]); + E += (h₂ᵢ + h₂ᵢ₊₁) / 6 * ( + (2 - h₂ᵢ₊₁ / h₂ᵢ) * f₂ᵢ + + pow(h₂ᵢ + h₂ᵢ₊₁, 2) / (h₂ᵢ * h₂ᵢ₊₁) * f₂ᵢ₊₁ + + (2 - h₂ᵢ / h₂ᵢ₊₁) * f₂ᵢ₊₂ + ); + } + E *= β; + + std::cerr << β << " " << μ << " " << Ct[0].real() << " " << E << std::endl; β += Δβ; } for (unsigned i = 0; i < N; i++) { - std::cout << fft.t(i) << " " << Rt[i].imag() << std::endl; + std::cout << fft.t(i) << " " << C[i] << std::endl; } return 0; -- cgit v1.2.3-70-g09d2