JuliaApproximation / ApproxFunFourier.jl

Support for Fourier-based spaces in ApproxFun
MIT License
7 stars 5 forks source link

Evaluating functions at 0 always returns 0 #125

Closed Jilhg closed 3 days ago

Jilhg commented 1 month ago

I noticed that for some periodic segments evaluating a function at 0 always produces 0. For instance

xmin,xmax=-2,3
S=CosSpace(xmin..xmax)

g=Fun(S,[1.0])
xs=LinRange(xmin,xmax,101)
plot(xs,g)

has the following output image

This is caused because 0 is apparently not contained in the periodic segment:

0∈domain(S) # False

which is checked before function evaluation (ApproxFunFourier.jl, l.267).

The following code in Domains.jl is responsible for this behavior:

function indomain(x, d::PeriodicDomain{T}) where T
    y=tocanonical(d,x)
    if !isapprox(fromcanonical(d,y),x)
        return false
    end
    ...
end

If x=0 then fromcanonical(d,y)= 1.1102230246251565e-16 and thus isapprox returns false. I guess one way of solving this issue would be to specify an atol=... in isapprox.

jishnub commented 1 month ago

Would you mind making a PR?

Jilhg commented 1 month ago

I can do, what value of atol should I choose? 1e-15? Feels a bit hacky, I guess there will always be some x that are not covered. I could also overload indomain specifically for PeriodicSegments?