Maybe you should specify the required precision in the problem description.
OK, I added a sentence, thanks.
different matlab fnction used to solve this problem
lol ! need a translator for this solution!
This solution should provide minimal rounding error since it's done in an essentially symbolic domain and then evaluated at the very end, but it doesn't satisfy the test cases. *sigh*
The sequence is strictly positive. (Not easy to see, but true). If your pn's get negative at some higher n, you still have the roundoff problem. It would be indeed avoided if the integer calculation within the loop was exact, but the numbers quickly become larger than the 48bit mantissa of a double.
686 Solvers
Program an exclusive OR operation with logical operators
639 Solvers
Project Euler: Problem 2, Sum of even Fibonacci
835 Solvers
58 Solvers
Replace all zeros and NaNs in a matrix with the string 'error'
90 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!