Write a function called max_sum that takes v, a row vector of numbers, and n, a positive integer as inputs. T is the largest possible. In other words, if v is [1 2 3 45 43 2 1] and n is 3, it will...


Write a function called max_sum that takes v, a row<br>vector of numbers, and n, a positive integer as inputs. T is<br>the largest possible. In other words, if v is [1 2 3 45 43 2<br>1] and n is 3, it will find 4 5 and 4 because their such<br>sequences exist in v, max_sum returns the first one. The<br>function returns summa, the sum as the first consecutive<br>ones as the second output. If the input n is larger than the<br>number of elements of v, the function runs:<br>[summa, index] = max_sum([1 2 3 4 5 4 3 2 1],3)<br>%3D<br>summa =<br>13<br>index = 4<br>[summa, index] = max_sum([1 2 3 4 5 4 3 2 1],2)<br>summa = 9<br>index = 4<br>[summa, index] = max_sum([1 2 345 4 3 2 1],1)<br>summa<br>5<br>index = 5<br>%3D<br>[summa, index] = max_sum([1 2 3 4 5 4 3 2 1],9)<br>summa = 25<br>index = 1<br>[summa, index] = max_sum([1 2 3 4 5 4 3 2 1],10)<br>summa =<br>index = -1<br>

Extracted text: Write a function called max_sum that takes v, a row vector of numbers, and n, a positive integer as inputs. T is the largest possible. In other words, if v is [1 2 3 45 43 2 1] and n is 3, it will find 4 5 and 4 because their such sequences exist in v, max_sum returns the first one. The function returns summa, the sum as the first consecutive ones as the second output. If the input n is larger than the number of elements of v, the function runs: [summa, index] = max_sum([1 2 3 4 5 4 3 2 1],3) %3D summa = 13 index = 4 [summa, index] = max_sum([1 2 3 4 5 4 3 2 1],2) summa = 9 index = 4 [summa, index] = max_sum([1 2 345 4 3 2 1],1) summa 5 index = 5 %3D [summa, index] = max_sum([1 2 3 4 5 4 3 2 1],9) summa = 25 index = 1 [summa, index] = max_sum([1 2 3 4 5 4 3 2 1],10) summa = index = -1

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here