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 =
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...
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F40a9514d-d7ca-4467-8320-3b6e9b54f257%2Fe8aafff5-ab47-4c4c-a999-745b9367aa52%2Fhh5mzjc_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images

Recommended textbooks for you

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY