Problem 12. Fibonacci sequence
very basic problem
basic... but where is the description of the Fibonacci series?
lim_n->(inf) of fib(n+1)/fib(n)=golden ratio :0
Only size matters?
I have tested tic toc time for 4 kinds of solutions I have seen for this problem. I have computed 1e5 fibonacci numbers f(n) with n<=70 picked at random. Here are the results:
1) Explicit formula (sltn 408159, size 42): 3.83e-01 s. \\
2) for loop (sltn 409425, size 36): 1.09e-01 s. \\
3) filter (sltn 409380, size 33): 4.78e-01 s. \\
4) Recursion (sltn 408916, size 31): inifinity
fibonacci, a math out of gods creation
I remember we did this in highschool ))
Really the most awful problem. Add f=whateverucalledthevector(n) at the end to make the script work.
give me a new think about numbers
I am unsure why this code is not working.
function f = fib(n)
X=['f is ',num2str(age)];
this is cool xd
The size 10 solutions all involve a regexp hack that essentially injects arbitrary code of size 1. The following is size 10:
Bottom line, anything of size 10 is sneaking past a weakness in the size algorithm.
Here's a size 23 legit solution I came up with. It's based on expressing F(n+2)-F(n+1)+F(n) in the form of a 2x2 matrix, [1 1;1 0]. It turns out that using that form explicitly, I got down to size 24. That matrix can be expressed one size smaller as mod(pascal(2),2), 2-pascal(2), or magic(2)~=2, and likely other forms. And OBTW, it works for zero and negative numbers as well!
function f = fib(n)
Good explanation of the problem. I am new to cody but I was able to understand easily the input and output format of the problem.
function y = fib(n)
y = ((((1+sqrt(5))/2)^n)-(((1-sqrt(5))/2))^n)/sqrt(5);
would you please give me hint that why it doesn't work ?
Solution CommentsShow comments
Problem Recent Solvers12365
Remove the polynomials that have positive real elements of their roots.
The sum of the numbers in the vector
Sum of first n positive integers
Is this triangle right-angled?
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!