In: Computer Science
Create a function to output a one dimensional double array M with n elements where the first three elements are 1 and each subsequent element is the sum of previous three elements before it. Name the function myArray. Write the function in the correct format to be used to create a Matlab function. Call the function in correct format to output the array with 7 elements.
code :
output :
raw_code :
function M = subsequent(n)
M = double([1,1,1,]); %assigning first three elements to 1
for i = n-3:n
M(i) = M(i-1)+M(i-2)+M(i-3); %adding previous three numbers
end
end