Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect results for sin and cosine functions #939

Closed
ay111 opened this issue Apr 5, 2024 · 2 comments
Closed

Incorrect results for sin and cosine functions #939

ay111 opened this issue Apr 5, 2024 · 2 comments

Comments

@ay111
Copy link

ay111 commented Apr 5, 2024

ApproxFun (version 0.13.26) returns incorrect values for sine and cosine of some known angles in Julia 1.10. See the examples below.

julia> using ApproxFun

julia> f = Fun(cos)
Fun(Chebyshev(), [0.765198, 0.0, -0.229807, 0.0, 0.00495328, 0.0, -4.18767e-5, 0.0, 1.88447e-7, 0.0, -5.26123e-10, 0.0, 9.99916e-13])

julia> f(pi) # correct answer is -1
0.0

julia> f(2pi) # correct answer is 1
0.0

julia> g = Fun(sin)
Fun(Chebyshev(), [0.0, 0.880101, 0.0, -0.0391267, 0.0, 0.000499515, 0.0, -3.00465e-6, 0.0, 1.04985e-8, 0.0, -2.39601e-11, 0.0, 3.85525e-14])

julia> g(pi/2) # correct answer is 1
0.0

julia> g(3pi/2) # correct answer is -1
0.0

@jishnub
Copy link
Member

jishnub commented Apr 5, 2024

The issue here is that the values lie outside the domain, and a Fun does not extrapolate (it always evaluates to zero outside the domain). You probably want to define it on a larger domain. By default, the domain is -1..1, corresponding to the Chebyshev interval.

For example:

julia> g = Fun(sin, -2pi..2pi)
Fun(Chebyshev(-6.283185307179586 .. 6.283185307179586), [0.0, -0.424765, 0.0, -0.0582244, 0.0, 0.745649, 0.0, -0.315042, 0.0, 0.0582478    0.0, -1.38959e-11, 0.0, 2.35992e-13, 0.0, -3.4972e-15, 0.0, -2.60209e-17, 0.0, -6.93889e-17])

julia> g(pi/2)
1.0

@ay111
Copy link
Author

ay111 commented Apr 5, 2024 via email

@jishnub jishnub closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants