The Fibonacci sequence is an integer sequence calculated by adding the previous two numbers together to calculate the next value. This is represented mathematically by saying that Fn = Fn-1 + Fn-2 (where Fn is the nth value in the sequence).
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13
8 + 13 = 21
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 be 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 Fn = Fn-1 + Fn-2 + Fn-3 (where Fn is the nth value in the sequence).
0 + 1 + 2 = 3
1 + 2 + 3 = 6
2 + 3 + 6 = 11
3 + 6 + 11 = 20
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. The function should accept one input argument, the length of the desired Bowman sequence to generate, and return one output variable, the Bowman sequence stored in a row vector. This function should also check to see if the number passed into the function is a valid Bowman sequence.