The Bowman sequence is an integer sequence calculated by add
The Bowman sequence is an integer sequence calculated by adding the previous 3 numbers
together to calculate the next value. This is represented mathematically by saying that Fn =
Fn1 + Fn2 + Fn3 (where Fn is the nth value in the sequence, F). For example, a Bowman
sequence of length 8 will be:
0 1 2 3 6 11 20 37
Note that this sequence always starts with the underlined values (0,1,2).
Write a MATLAB program that will:
a) Request the user for the length of the desired Bowman sequence to generate.
b) Display an error message and terminate if the input is invalid (for example, -8).
c) Return an array containing the Bowman sequence of the input length if the input is valid.
Solution
clc;
clear all;
close all;
prompt = \'Enter Length of Bowman sequence : \'; % Asking user enter length of the series
B_Length= input(prompt);
Bowman=[0 1 2];
if B_Length<=0
fprintf(\'\ Invalid Input.\ \');
else
for i=4:1:B_Length
Bowman(i)=Bowman(i-1)+Bowman(i-2)+Bowman(i-3);
end
fprintf(\' Bowman sequence of length %d given by\ \',B_Length);
Bowman
end
OUTPUT:
Enter Length of Bowman sequence : -6
Invalid Input.
 >>
-------------------
Enter Length of Bowman sequence : 12
 Bowman sequence of length 12 given by
 Bowman =
 0 1 2 3 6 11 20 37 68 125 230 423
 >>


