Write a function max_product that takes v a vector and n, a positive integer, as inputs and computes the largest product of n consecutive elements of v

Write a function max_product that takes v a vector and n, a positive integer, as inputs and computes the largest product of n consecutive elements of v. It returns the product and the index of the element of v that is the first term of the product. If there are multiple such products in v, the function must return the one with the smallest starting index. As an example, the following call
>> [product, ind] = max_product([1 2 2 1 3 1],3);
will assign 6 to product and 3 to ind since the max 3-term product in the input vector is 2*1*3. If v has fewer than n elements, the function returns 0 and -1, respectively.


 

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

PLACE THIS ORDER OR A SIMILAR ORDER WITH homework handlers TODAY AND GET AN AMAZING DISCOUNT

get-your-custom-paper

The post Write a function max_product that takes v a vector and n, a positive integer, as inputs and computes the largest product of n consecutive elements of v appeared first on homework handlers .