Fibonacci function not accepting 0 and not displaying the last term only
问题 I wrote a function that displays the Fibonacci sequence up to the nth term. The code runs fine, but I want to make two changes and am not sure how to do so. Here is my code: function [ F ] = get_fib( k ) F(1) = 1; F(2) = 1; i = 3; while k >= i; F(i) = F(i-1) + F(i-2); i = i + 1; end end The first problem is that the code does not accept 0 as an input. I tried changing the function to: function [ F ] = get_fib( k ) F(0) = 0; F(1) = 1; F(2) = 1; i = 3; while k >= i; F(i) = F(i-1) + F(i-2); i =