How do I do number 4 this is matlab [total ind] = hw4_problem1([ XXXXXXXXXX],3)total =113ind =4Write a function called hw4_problem2 that takes a vector v as input. The function checks whether...


How do I do number 4 this is matlab


3. Problems<br>Write a function called hw4 problem1 that takes two inputs: a vector v and a positive integer scalar n. You do NOT need to check<br>these assumptions. The function needs to find the n consecutive elements in v whose sum is the maximum. It needs to return the<br>sum and the index of the first of these elements. If there are multiple such n consecutive elements in v, it returns the first one,<br>i.e., the one with the smallest index. Here is an example run:<br>1.<br>> [total ind] = hw4_problem1([1 2 3 4 5 4 3 2 1],3)<br>total =<br>1<br>13<br>ind =<br>4<br>Write a function called hw4_problem2 that takes a vector v as input. The function checks whether the elements of v are<br>monotonically non-decreasing or not. In other words, any element of v must not be smaller than the previous element.<br>The function returns a logical true if the condition holds and false otherwise. The function also returns a logical false<br>if the input is not a vector (or scalar).<br>2.<br>Write a function called hw4_problem3 that takes k, a positive integer scalar as an input (you do not need to check this).<br>The function returns p, the smallest prime number smaller than 1000 such that p+k is also prime. If no such prime<br>exists, the function returns 0. You may use the built-in functions primes and/or isprime.<br>3.<br>2<br>4. Write a function called hw4 problem4 that computes a sum as defined below. The function returns the smallest n such that the<br>sum is greater than the single input argument called limit. As a second output, the function also returns the corresponding sum.<br>1<br>1<br>1<br>1<br>= 1+=+ =+<br>2<br>S =<br>+<br>k<br>4<br>k=1<br>You are not allowed to use for loops. Here are a few examples:<br>>> [n s] = hw4_problem4 (1)<br>2<br>S =<br>1.500000000000000<br>» [n s] = hw4_problem4 (2)<br>n =<br>4<br>S =<br>2.083333333333333<br>>> [n s] = hw4_problem4 (8)<br>n =<br>1674<br>

Extracted text: 3. Problems Write a function called hw4 problem1 that takes two inputs: a vector v and a positive integer scalar n. You do NOT need to check these assumptions. The function needs to find the n consecutive elements in v whose sum is the maximum. It needs to return the sum and the index of the first of these elements. If there are multiple such n consecutive elements in v, it returns the first one, i.e., the one with the smallest index. Here is an example run: 1. > [total ind] = hw4_problem1([1 2 3 4 5 4 3 2 1],3) total = 1 13 ind = 4 Write a function called hw4_problem2 that takes a vector v as input. The function checks whether the elements of v are monotonically non-decreasing or not. In other words, any element of v must not be smaller than the previous element. The function returns a logical true if the condition holds and false otherwise. The function also returns a logical false if the input is not a vector (or scalar). 2. Write a function called hw4_problem3 that takes k, a positive integer scalar as an input (you do not need to check this). The function returns p, the smallest prime number smaller than 1000 such that p+k is also prime. If no such prime exists, the function returns 0. You may use the built-in functions primes and/or isprime. 3. 2 4. Write a function called hw4 problem4 that computes a sum as defined below. The function returns the smallest n such that the sum is greater than the single input argument called limit. As a second output, the function also returns the corresponding sum. 1 1 1 1 = 1+=+ =+ 2 S = + k 4 k=1 You are not allowed to use for loops. Here are a few examples: >> [n s] = hw4_problem4 (1) 2 S = 1.500000000000000 » [n s] = hw4_problem4 (2) n = 4 S = 2.083333333333333 >> [n s] = hw4_problem4 (8) n = 1674
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here