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...
Recall the Fibonacci sequence: 1,1,2,3,8,13.... In general we can generate Fibonacci-like sequences by making linear combinations...
Recall the Fibonacci sequence: 1,1,2,3,8,13.... In general we can generate Fibonacci-like sequences by making linear combinations of the formula that gives us the nth term of the sequence.Consider the following general case for generating Fibonacci-like sequences: F 1 = 1 F 2 = 1 Fn =  aFn-1 + bFn-2 where a, b are integers . Write a function that given values a, b and n will print a Fibonacci-like sequence up to the nth term of the sequence. ( eg, if...
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in...
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not...
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT