ApproxFun.jl icon indicating copy to clipboard operation
ApproxFun.jl copied to clipboard

Integration of a function in default and Fourier spaces give incorrect results

Open seadra opened this issue 3 years ago • 1 comments

Integration in the default (Chebyshev between [-1,1], maybe?) and Fourier spaces gives incorrect results in the following code. Using Chebyshev with explicit bounds gives the correct result.

Sθ=PeriodicSegment(-π,π);
fn = Fun(θ -> sin(θ), Sθ);
D2 = Derivative(Sθ, 2);
L = -D2-10fn;
λ, v = ApproxFun.eigs(L, 500, tolerance=1E-10);

integrand = Fun(θ -> sin(θ)*v[1](θ)*v[2]'(θ) ); # seems to be Chebyshev, but somehow give incorrect result
integrand_fourier = Fun(θ -> sin(θ)*v[1](θ)*v[2]'(θ), Fourier(-π..π)); # incorrect
integrand_chebyshev = Fun(θ -> sin(θ)*v[1](θ)*v[2]'(θ), Chebyshev(-π..π)); # correct

println(integrate(integrand)(π)-integrate(integrand)(-π));
println(integrate(integrand_fourier)(π)-integrate(integrand_fourier)(-π));
println(integrate(integrand_chebyshev)(π)-integrate(integrand_chebyshev)(-π));

This outputs

0.0
0.0
2.42716878621213

seadra avatar May 24 '21 01:05 seadra

julia> integrand = Fun(θ -> sin(θ)*v[1](θ)*v[2]'(θ) );

julia> domain(integrand)
-1.0..1.0 (Chebyshev)

The domain isn't correct in this case

jishnub avatar Oct 06 '22 06:10 jishnub