For any x in the range 0 < x and x < 2*pi radians, find the sum of the following infinite series:
c = 1 + 1/2*cos(x) + 1/2*3/4*cos(2*x) +
1/2*3/4*5/6*cos(3*x) + 1/2*3/4*5/6*7/8*cos(4*x) + ...
as a function of the form c = infinite_series2(x).
A nice problem. But the singularity provides a domain where a variable loss of precision is observed. Several formulae, which are mathematicaly equivalent and computationaly careful, give distinct results. Guessing the one that was used is the second step of the problem, and maybe the most difficult.
The answer for the third test case seems to be a little off.
i agree; my solution on the third and fifth test cases are showing up as incorrect even though I'm using an analytical form of the solution for this problem.
agree, I am getting 182.574870487881 and 306.940139754640 for the third and fifth cases, respectively; I guess we are supposed to find a way to better approximate around the singularity (for the x~=2*pi*n cases)?
I no longer take issue with test case 5, but I'm finding that it does not take care of test case 3.
Results for case 3 (x=6.28318) from Mathematica, a typical Matlab closed-form solution, and the test suite are
306.9401397805991 test suite
The result near 2*pi is a function of the difference between the input and 2*pi; since 6.28318 is equal to 2*pi to 6 digits, when you subtract 2*pi from it
you lose 6 digits of accuracy; the error tolerance should be set to about 10^6*eps to be fair for this case.
This is not peculiar to this function--here are results for sin(6.28318) from
Mathematica and Matlab:
Again you lose about 6 digits of accuracy in Matlab.
I have a closed form for the series and I'm having problems with test case 3...It seems that I joined the club...
There seems to be agreement that test case 3 has issues. Since the original author never returned, I commented out that test case.
I hope no one is offended by this. Based on the comments there was potentially something wrong with the test cases anyway, so the reference and solution seemed appropriate.
meh, i should have thought of it sooner
I get pass all the tests except for Test 3, where I get 306.9401397549153. My solution is based on a closed form solution, so I don't see how it's wrong. It is also equivalent to the results from Mathematica.
join the club
Swap the input arguments
Number of Circles in a Number
Raise Matrix to Power
Find the hypotenuse
Volume of a box
Compute Area from Fixed Sum Cumulative Probability
Subdivide the Segment
Sum the Infinite Series
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office