1. Write a function called hwd_probleml 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, ie, the one with the smallest index. Here is an example run: » (total ind) - hwd_probleml([1 2 3 4 5 4 32 1,3) total - 13 ind =

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

How do I do number 1 this is matlab

```markdown
### 3. Problems

1. **Problem 1:** 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 `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:
    ```matlab
    >> [total ind] = hw4_problem1([1 2 3 4 5 4 3 2 1], 3)
    total =
        13
    ind =
        4
    ```

2. **Problem 2:** 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).

3. **Problem 3:** Write a function called `hw4_problem3` that takes `x`, 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+x` is also prime. If no such prime exists, the function returns 0. You may use the built-in functions `primes` and/or `isprime`.

4. **Problem 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.
   \[
   S = \sum_{k=1}^{n} \frac{1}{k} = 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \ldots 
   \]
   
   You are not allowed to use for loops.
Transcribed Image Text:```markdown ### 3. Problems 1. **Problem 1:** 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 `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: ```matlab >> [total ind] = hw4_problem1([1 2 3 4 5 4 3 2 1], 3) total = 13 ind = 4 ``` 2. **Problem 2:** 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). 3. **Problem 3:** Write a function called `hw4_problem3` that takes `x`, 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+x` is also prime. If no such prime exists, the function returns 0. You may use the built-in functions `primes` and/or `isprime`. 4. **Problem 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. \[ S = \sum_{k=1}^{n} \frac{1}{k} = 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \ldots \] You are not allowed to use for loops.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY