Problem 12. Fibonacci sequence
解决方案Stats
Problem Comments
-
14 Comments
very basic problem
基本...但是斐波那契系列的描述在哪里?
lim_n->(inf) of fib(n+1)/fib(n)=golden ratio :0
((((((((((((1+sqrt(5)),))^n) - ((((((((1-sqrt(5)))))
Only size matters?
我已经测试了TIC TOC时间的时间,以解决此问题的4种解决方案。万博 尤文图斯我已经计算了1e5 fibonacci数字f(n),n <= 70随机选择。这是结果:
1)显式公式(SLTN 408159,尺寸42):3.83E-01 s。\\
2)用于循环(SLTN 409425,尺寸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 ))
真的是最糟糕的问题。添加f =末尾的任何callucalledthevector(n)以使脚本工作。
好问题。
easy
Interesting one!
give me a new think about numbers
I am unsure why this code is not working.
function f = fib(n)
f (1) =1;
f(2)=1;
for i=3:n
(我)= f (i-1)+f(i-2);
end
age=f(n);
x = ['f is',num2str(age)];
disp(X)
end
this is cool xd
解决方案评论
-
1 Comment
easy. classical iteration problem. solving this problem is easy, but iteration is hard to master.
-
2 Comments
hahahahah
Classic!
-
2 Comments
Is there a shorter way?
是的。
Also this solutions will fail fib(0)
-
2 Comments
I broke Cody server with this.
function f = fib(n)
a = [0 1];
indx = n-1;
if n==0
f=a(1);
elseif n==1
f=a(2);
else
while indx <= n
a(indx+1)=fib(n-1)+fib(n-2);
indx = indx+1;
end
f=a(n);
end
我的大小是-1不应该赢吗?
When you want to calculate fib(1), it calls fib(0) + fib(-1). There is no fib(-1) so you never leave the while loop.
-
2 Comments
function f = fib(n)
c =[1 2];
for i=1:n
c(i+2)= c(i)+c(i+1)
end
f = c(:,i)
end
could anybody please give me hint. I am struck here
f(1) fails. All other cases passed
将C = [1 2]更改为C = [1 1]
-
1 Comment
i wrote a code just like i would in c++. The code is huge by size but the answers are right however cody seems to disagree.
-
1 Comment
nice task
-
1 Comment
nice
-
1 Comment
为什么fibonacci功能在这里不起作用?
-
1 Comment
Can someone explain about the solution size please..
-
1 Comment
good job
-
1 Comment
这太容易了
-
1 Comment
The Test Suite should include a check using random integer inputs to prevent simple indexing to generate a solution.
-
1 Comment
我认为我的代码没有任何错误.......
-
1 Comment
很容易
-
1 Comment
很容易
-
1 Comment
.
-
1 Comment
i had to add a line of code because you didnt expect the number to be a float rather then an integer so it counted my last test as wrong all because it had .000 at the end of each one.
-
2 Comments
I tried this one in MATLAB and it worked but here it keeps displaying assertion failed for every number different from 1
因为您使用的是浮点计算,所以结果可能不准确。如果您将结果围绕到最近的整数,则应起作用。
-
1 Comment
fibonacii系列OS OS该系列,其中每个数字是先前数字的总和
-
2 Comments
-
2 Comments
Not sure what went wrong...
Put this at the end (between the two 'end's)
f = f(n);
-
1 Comment
:)
-
1 Comment
我什至没有考虑走递归路线。现在似乎很明显。
-
1 Comment
我正在使用平方纤维契数的属性。
-
1 Comment
对齐在这里是一个问题:)
-
1 Comment
Yay recursion
-
2 Comments
-
1 Comment
Testsuite seems to have problem for value n=1
-
4 Comments
这确实是一个精神上的挑战
I don't understand why the size of this code is so huge, can anyone help ?
Hi all,
I have used regular expressions in other languages before but not in MATLAB. Can someone explain the solution to me? I have looked up the format of regexp in the help file, but the use of the regexp in the solution does not seem to fit the description in help.
当我尝试在八度中运行代码时,它会出现错误,因为它无法识别“无效调用Regexp”错误。
Can someone please help!
Nice !
-
2 Comments
problem in the test suite my Solution was perfect, please update the test suite
我不确定您是如何得出的。给出的示例说FIB(5)应为5。您的代码返回15。
-
1 Comment
这被打破了:我急于在第一个版本中修复错字,我不小心用1个错误的2替换了错误的2。
-
3 Comments
我不明白为什么这不正确。
I got the equation from 1) and the calculations are correct when I use Matlab at home (see 2)).
1) https://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form
2)https://en.wikipedia.org/wiki/fibonacci_number#list_of_fibonacci_numbers
如果您返回地板(F),这将起作用。
Thank you =)
-
1 Comment
这是一个很好的答案。比'圆(1.61803^n /2.236)更好。如果n> 24,后者是错误的。
-
1 Comment
编程中的递归........................
-
3 Comments
-
3 Comments
-
1 Comment
i want to know how does the second line work , i don't understand the reslut ,can u help???,
-
2 Comments
该解决方案在n = 23之后不起作用。
It's still one hell of a hack! :)
Problem Recent Solvers11225
建议的问题
1404 Solvers
597求解器
解决461
3240 Solvers
631个求解器
来自作者的更多95
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!