Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Fibonacci sequence is an integer sequence calculated by adding previous numb

ID: 3815940 • Letter: T

Question

The Fibonacci sequence is an integer sequence calculated by adding previous numbers together to calculate the next value. This is represented mathematically by saying that F_n = F_n - 1 + F_n-2 (where F_n is the nth value in the sequence, F) or Note this sequence starts with the underlined values (0, 1) and calculates the remaining values in the sequence based on the sum of the previous two values. Professor Bowman found this sequence to extremely insufficient and created the Bowman sequence, which is an integer sequence calculated by adding the previous three numbers together (instead of two like in the Fibonacci sequence) to calculate the next value. This is represented mathematically by saying that F_n = F_n - 1 + F_n - 2 + F_n - 3 (where F_n is the nth value in that the sequence, F) or: Note this sequence starts with the underlined values (0, 1, 2) and calculates the remaining values in the sequence based on the sum of the previous three values. Write a MATLAB function that implements the Bowman sequence that accepts one input argument, the length of the desired Bowman sequence to generate, and returns one output variable, the Bowman sequence stored inside of an array. This function should also check to see if the number passed in to the function is a valid Bowman sequence length (think about what might constitute valid sequence lengths!). If the input is invalid, your function should display an error message and the output variable should contain only one number: -1. Otherwise if the input is valid, your function should calculate the Bowman sequence and display each value in the sequence in the Command Window. Sample Output: >> B = FUNCTIONNAME (8) ; Bowman sequence: 0 1 2 3 6 11 20 37

Explanation / Answer

%% Bowman: function description
function [outputs] = bowman(n)
   if n <= 0
       outputs = [-1];
       return
   end
   outputs = 0:(n-1);
   for i = 4:n
       outputs(i) = outputs(i-1)+outputs(i-2)+outputs(i-3);
   end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote