JuliaApproximation / ApproxFun.jl

Julia package for function approximation
http://juliaapproximation.github.io/ApproxFun.jl/
Other
541 stars 70 forks source link

Completely Wrong Evaluation at Point Near Zero for Fourier Series #947

Open cdstephens opened 4 days ago

cdstephens commented 4 days ago

I am trying to use Optim.jl for univariate functions in tandem with ApproxFun.jl. However, there is a catastrophic bug that requires an awkward workaround. When I evaluate a Fourier series at a point close to zero, ApproxFun gives a completely incorrect result. Below is the minimal code that demonstrates this.

Input:

using ApproxFun
dF = Fourier(-pi..pi)
example = Fun(x -> cos(x), dF)
val_correct = example(0)
val_correct_2 =  example(2*pi + 1e-09)
val_wrong = example(1e-09)

Result:

Fourier(【-3.141592653589793,3.141592653589793❫)
Fun(Fourier(【-3.141592653589793,3.141592653589793❫), [5.62263e-17, -2.77556e-17, -1.0])
1.0
1.0
2.775556218710621e-26

This has also occurred for more complicated functions. Essentially, if I evaluate a Fourier series at some very small x, then the output will be close to zero. Here, 1e-09 is not particularly close to machine precision, so I can't see why this should be happening.

jishnub commented 3 days ago

The issue seems to be that

julia> 1e-9 ∈ domain(example)
false

This should be true