function out = fibonacci(n, fibprevious)
if (n == 1)
    out = 0;
elseif (n == 2)
    out = 1;
elseif (fibprevious(n) ~= 0)
    out = fibprevious(n);
else
   
  fibprevious(n) = fibonacci(n-1, fibprevious) + fibonacci(n-2, fibprevious);
  out = fibprevious(n);
end