SUNY Geneseo Department of Mathematics
Wednesday, March 9
Math 230 02
Spring 2016
Prof. Doug Baldwin
function [ F ] = fib( n )
%FIB Compute nth Fibonacci number
if ( n == 0 )
F = 0;
elseif ( n == 1 )
F = 1;
else % n > 1
F = fib( n-1 ) + fib( n-2 );
end
end
>> fib(1)
ans =
1
>> fib(3)
ans =
2
>> fib(6)
ans =
8
>> x = 10
x =
10
>> % 0 <= x <= 1?
>> 0 <= x <= 1
ans =
1
>> % Something is wrong: 10 is clearly not between 0 and 1
>> 0 <= x & x <= 1
ans =
0
>> % This expression produced the correct result