Fibonacci serie, can not calculate with big number

function area = triangle_sequence(n)
% Fibonacci% Fibonacci
if n == 1
area= 25
elseif n == 2
area = 25 +16
else
area = triangle_sequence(n-1)+ triangle_sequence(n-2)
end
end
My matlab can not stop while n= 50. I need help !

댓글 수: 1

My matlab can not stop while n= 50
It's not suprising, for n=50 you'd be calling your triangle_sequence function about 28 trillion times (28,000,000,000). The time complexity of the naive implementation of the fibonacci sequence is exponential. There are plenty of more efficient algorithms easily accessible with a simple web search.

댓글을 달려면 로그인하십시오.

답변 (2개)

Ollie A
Ollie A 2019년 1월 31일

0 개 추천

If you're trying to calculate numbers in the Fibonacci series, there is a MATLAB function for it:
If this doesn't help please could you explain your question in more detail?

댓글 수: 4

HAAAAH
HAAAAH 2019년 1월 31일
my homework requires that i have to do my own function. I have to calculat area of a triangle and the start the first triangle area will be 25 and second one is 25+16 , third : 25+25+16 , and n = (area av n-1 ) + (area av n-2).
M = [16,25];
for n = 1:100
M = [M,sum(M)];
end
madhan ravi
madhan ravi 2019년 2월 1일
편집: madhan ravi 2019년 2월 1일
Don‘t do obvious homework problems! Give hints instead.
I agree with Madhan, giving straight solutions to homework problems is not a good idea. The students don't learn anything from it (and it can get them into trouble if they actually use the solution).
However, in this case, the solution is wrong anyway.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2019년 1월 31일

댓글:

2019년 2월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by