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

Slightly inaccurate when integrating over floor/ceil. #30

Open
fwip opened this issue May 30, 2021 · 5 comments
Open

Slightly inaccurate when integrating over floor/ceil. #30

fwip opened this issue May 30, 2021 · 5 comments

Comments

@fwip
Copy link

fwip commented May 30, 2021

I'm not sure if this is a known limitation or something that should be an issue. I suspect it applies to all step-wise functions but I haven't checked.

>> ∫ (0, 1, ⌈x⌉, dx)
0.9995833333

This should be 1 exactly, but I suspect that the code falls back to numerical integration in these cases.

More examples:

>> ∫ (1/10000, 1, ⌈x⌉, dx)
0.9999 # correct
>> ∫ (1/100000, 1, ⌈x⌉, dx)
1  # should be 0.99999
>> ∫ (1/1000000, 1, ⌈x⌉, dx)
1 # should be 0.999999
>> ∫ (1/10000000, 1, ⌈x⌉, dx)
1.0004165666   # over one? should be 0.9999999
@PaddiM8
Copy link
Owner

PaddiM8 commented May 30, 2021

Well, integration will often not be perfectly accurate, since functions can really vary a lot. Sometimes it's spot on, sometimes it's not. in this case, it looks like it's related to floating point numbers not being perfectly accurate, since it gets less accurate when you have numbers like 1/100000. This is the kind of thing I'm interested in making more accurate though, so this is a great example! It appears to be just slightly better (for me at least) on the desktop version, that is better at dealing with very large/very small numbers. Eventually, I'd like this to be the case for the web version as well, but the language it's written in (Rust) seems to lack a mature library for this.

@fwip
Copy link
Author

fwip commented May 30, 2021

Makes sense, thank you for the quick reply! Please feel free to close this issue if it is not useful to you to have it open. :)

@MitsuhaMiyamizu
Copy link

Hi, I encountered the same result just like this one

Given
∫(-2,2,(√(4-x^2))*(1/2+x^3*cos(x/2))dx)

We suppose to get the result pi, which is 3.1415926535897
However, I got 3.1415340713 using Kalk

Is there something that can be improved in the future?
Many thanks.

@PaddiM8
Copy link
Owner

PaddiM8 commented May 31, 2021

Hi, I encountered the same result just like this one

Given
∫(-2,2,(√(4-x^2))*(1/2+x^3*cos(x/2))dx)

We suppose to get the result pi, which is 3.1415926535897
However, I got 3.1415340713 using Kalk

Is there something that can be improved in the future?
Many thanks.

Ah. Well, when it comes to more "complicated" ones like this, it may be difficult to get more accuracy. It can always be tweaked though, and maybe made more flexible. I'll look into it!

@timokoesters
Copy link
Contributor

∫ (1/10000000, 1, ⌈x⌉, dx)
1.0004165666 # over one? should be 0.9999999

I can't reproduce this, it says ≈ 1 for me.

I think a good solution to this problem would be to add an optional parameter for the integrate function to set the accuracy.

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

4 participants