Fibonacci serie, can not calculate with big number

1 Ansicht (letzte 30 Tage)
HAAAAH
HAAAAH am 31 Jan. 2019
Kommentiert: Guillaume am 1 Feb. 2019
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 Kommentar
Guillaume
Guillaume am 31 Jan. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Ollie A
Ollie A am 31 Jan. 2019
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 Kommentare
madhan ravi
madhan ravi am 1 Feb. 2019
Bearbeitet: madhan ravi am 1 Feb. 2019
Don‘t do obvious homework problems! Give hints instead.
Guillaume
Guillaume am 1 Feb. 2019
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.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 31 Jan. 2019

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by