-
4 Comments
My code works to d=50 and fails on the higher values in the test suite. I think it is a hardware-limited rounding error (?swamping) with very large numbers. When I test eps(fibonacci(100)) on my system, the answer is 6.5 ie my system can not accurately distinguish odd from even at that large a number.
Leo, your theory is correct: The numbers that you're calculating for d>50 are too large to be represented by a 32-bit digit, and won't be calculated correctly for mod(x,2). Think very carefully about the number pattern in the Fibonacci sequence, and see if a pattern emerges.
Indeed, My code works until the d = 50 because it's a large number, so our algorithm is correct we should not worry about it, I think we have succeed in this challenge.
me too.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!