Question

Given: function f = fibonacci(n) % FIBONACCI Fibonacci sequence % f = FIBONACCI(n) generates the first...

Given:

function f = fibonacci(n)

% FIBONACCI Fibonacci sequence

% f = FIBONACCI(n) generates the first n Fibonacci numbers.

f = zeros(n,1);

f(1) = 1;

f(2) = 2;

for k = 3:n

f(k) = f(k-1) + f(k-2); end

AND

function f = fibnum(n)

if n <=1

f =1;

else

f = fibnum(n-1) + fibnum(n-2);

end

In Matlab, modify fibonacci.m and fibnum.m to compute the following sequence.

dn = 0, n<=0

d1 = 1,

d2 = 1

and, for n > 2,

dn = dn−1 + dn−2 − dn−7

Homework Answers

Answer #1

Modified MATLAB Code:

function d = fibonacci(n)
    d = zeros(n,1);
    d(1) = 1;
    d(2) = 1;
    
    for k = 3:min(n,7)
        d(k) = d(k-1) + d(k-2);
    end
    
    for k = 8:n
        d(k) = d(k-1) + d(k-2) - d(k-7); 
    end
    

function d = fibnum(n)
    if n <= 0
        d = 0;
    elseif n <= 2
        d = 1;
    else
        d = fibnum(n-1) + fibnum(n-2) - fibnum(n-7);
    end

Please refer to the following picture for the sample execution of the above code:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … The sequence Fn of Fibonacci numbers is defined by the recurrence relation: Fn = Fn-1 + Fn with seed values F1 = 1 F2 = 1 For more information on...
The Fibonacci series is given by; F0=0, F1=1,F2=1, F3=2,F4=3,…F(i)=F(i-1)+F(i-2) Given that r^2=r+1. Show that F(i) ≥...
The Fibonacci series is given by; F0=0, F1=1,F2=1, F3=2,F4=3,…F(i)=F(i-1)+F(i-2) Given that r^2=r+1. Show that F(i) ≥ r^{n-2}, where F(i) is the i th element in the Fibonacci sequence
In mathematical terms, the sequence Fn of Fibonacci numbers is 0, 1, 1, 2, 3, 5,...
In mathematical terms, the sequence Fn of Fibonacci numbers is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….. Write a function int fib(int n) that returns Fn. For example, if n = 0, then fib() should return 0, PROGRAM: C
Homework 6 Problem 2 Translate the third of the following three algorithms to C++. Write a...
Homework 6 Problem 2 Translate the third of the following three algorithms to C++. Write a program to test the function. The first few Fibonacci numbers are 1,1,2,3,5,8,13,21,34,55,89,144,… Fibonacci(n)    f1 = 0    f2 = 1    fib = 0    while n > 0      f1 = f2      f2 = fib      fib = f1 + f2      n = n – 1    end while    return fib end fibonacci fibonacci(n) if n < 1 then...
Fibonacci Sequence (Javascript in HTML)   function fib(first, second, countdown){     console.log("I was called with " + first...
Fibonacci Sequence (Javascript in HTML)   function fib(first, second, countdown){     console.log("I was called with " + first + ", " + second + ", " + countdown);         if(countdown>0){                                 fib(first,first+second, countdown-1);         }     }     fib(1,2,3); Now you get to figure out how to use the fib function to print the number sequence without using a loop in the function (hint, the function needs to call itself). How is this exactly done? It needs to be in written so I can input it into...
Please Write the whole program in assembly i am able to calculate the fibonacci series but...
Please Write the whole program in assembly i am able to calculate the fibonacci series but not sure how to print it in reverse order. Please give a Complete code !! Programming Exercise 1 (10 points): [call it Ass2-Q1.asm] Write an ASM program that reads an integer number N and then displays the first N values of the Fibonacci number sequence, described by: Fib(0) = 0, Fib(1) = 1, Fib(N) = Fib(N-2) + Fib(N-1) Thus, if the input is N...
For the general form of the Fibonacci sequence: Given a, b, and c. Let x0=a and...
For the general form of the Fibonacci sequence: Given a, b, and c. Let x0=a and x1=b. Define xn+2=cxn+1 + cxn. Compute several terms of this sequence collecting powers of c. Determine a pattern of the coefficients that involves the terms of Pascal’s triangle.
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1; (a)    Case 1, Assume K = 1 (b)    Case 2, Assume K = 2 (c)     Case 3, Assume K = 4 Plot all of these on the same plot, for N = 1 to 20
The Fibonacci sequence is defined as follows F0 = 0 and F1 = 1 with Fn...
The Fibonacci sequence is defined as follows F0 = 0 and F1 = 1 with Fn = Fn−1 +Fn−2 for n > 1. Give the first five terms F0 − F4 of the sequence. Then show how to find Fn in constant space Θ(1) and O(n) time. Justify your claims
A20) Given that f(x) is a cubic function with zeros at −2−2 and 2i−2, find an...
A20) Given that f(x) is a cubic function with zeros at −2−2 and 2i−2, find an equation for f(x) given that f(−7)=−6 B19) Find a degree 3 polynomial whose coefficient of x^3 equal to 1. The zeros of this polynomial are 5, −5i, and 5i. Simplify your answer so that it has only real numbers as coefficients. C21) Find all of the zeros of P(x)=x^5+2x^3+xand list them below with zeros repeated according to their multiplicity. Note: Enter the zeros as...