Problem 58259. Easy Sequences 115: Integral involving square root, floor, and round functions
Given a postive real number n, we are asked to evaluate the following integral:
We may rewrite the above function in Matlab as:
>> S = @(n) round(integral(@(x) sqrt(floor(x))-floor(sqrt(x)),0,n));
Therefore, for , we have:
>> s = S(10*pi)
s =
12
Be careful though, in using the Matlab integral function, as it is only an approximation. For example if :
>> s = S(100000)
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is
8.0e+01. The integral may not exist, or it may be difficult to approximate numerically to the
requested accuracy.
> In integralCalc/iterateScalarValued (line 372)
In integralCalc/vadapt (line 132)
In integralCalc (line 75)
In integral (line 87)
In @(n)round(integral(@(x)sqrt(floor(x))-floor(sqrt(x)),0,n))
s =
49841
The correct answer is . The integral function is off by only 2 units here, but the discrepancy could be even greater for other values of n. integral function can also be quite slow. The challenge is to find an efficient and more accurate algorithm to evaluate the integral.
Solution Stats
Problem Comments
-
1 Comment
Ramon Villamangca
on 18 May 2023
Hi David,
You right I should have use floor (34) instead of round (35). Test suites were adjusted. Thanks.
Solution Comments
Show commentsProblem Recent Solvers1
Suggested Problems
-
2246 Solvers
-
Find common elements in matrix rows
2633 Solvers
-
14040 Solvers
-
Simple equation: Annual salary
4185 Solvers
-
Is this is a Tic Tac Toe X Win?
511 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!