
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
![2. (a) Write a function, called myListFn, which takes a single argument n and implements the following
algorithm:
1. Simulate n independent numbers, denoted x = (x1, x2,..., xn), from the N(0, 1) distribution.
2. Calculate the mean X = E- Ti
n.
3. If x > 0, then simulate n independent numbers, denoted y (y1, y2,.. ., Yn), from the exponential
density with mean X.
If x < 0, then simulate n independent numbers, denoted z = (21, 2, ..., zn), from the exponential
density with mean -x. Set y = (y1, Y2, ..., Yn) = -z.
4. Calculate k which is the number of j with yj| > ]xj\.
5. Return the list of x, y and k with names xVec, yVec and count respectively.
(b) Execute the following lines and check the format of the answers:
lapply( rep(10,4), myListFn )
sapply( rep(10,4), myListFn )
Note that sapply is effectively lapply followed by simplify2array.
If myListFn has no arguments, then similar results can be obtained with replicate (4, myListFn())
and replicate(4, myListFn(), simplify=F).
Now for a simulation study. Use lapply to call the function myListFn with n = 10 for 1,000 times. So the
output consists of
10,000 values for x denoted {rij: i = 1,2,..., 1,000; j = 1, 2, ..., 10};
10,000 values for y denoted {y;jii = 1, 2, ..., 1,000; j = 1, 2,..., 10};
and 1,000 values for n denoted n1, n2,... , n1000-
Denote the output by myList. This output is used in the remaining parts of this question.
(c) Extract all the vectors with the name yVec. The result should be a list of 1000 vectors.
(d) Extract all the vectors with the name yVec. The result should be a 10 x 1000 matrix with one column
for each of the vectors yVec.
(e) Create a list which is identical to myList but all the components called count have been removed.
(f) Pick out those lists in myList which are such that count is greater than 2.](https://content.bartleby.com/qna-images/question/69992d9e-9ab1-41fc-a849-49585310b5a4/70ef5742-f49f-4640-9b77-122dcce0987b/bn76e8n_thumbnail.jpeg)
Transcribed Image Text:2. (a) Write a function, called myListFn, which takes a single argument n and implements the following
algorithm:
1. Simulate n independent numbers, denoted x = (x1, x2,..., xn), from the N(0, 1) distribution.
2. Calculate the mean X = E- Ti
n.
3. If x > 0, then simulate n independent numbers, denoted y (y1, y2,.. ., Yn), from the exponential
density with mean X.
If x < 0, then simulate n independent numbers, denoted z = (21, 2, ..., zn), from the exponential
density with mean -x. Set y = (y1, Y2, ..., Yn) = -z.
4. Calculate k which is the number of j with yj| > ]xj\.
5. Return the list of x, y and k with names xVec, yVec and count respectively.
(b) Execute the following lines and check the format of the answers:
lapply( rep(10,4), myListFn )
sapply( rep(10,4), myListFn )
Note that sapply is effectively lapply followed by simplify2array.
If myListFn has no arguments, then similar results can be obtained with replicate (4, myListFn())
and replicate(4, myListFn(), simplify=F).
Now for a simulation study. Use lapply to call the function myListFn with n = 10 for 1,000 times. So the
output consists of
10,000 values for x denoted {rij: i = 1,2,..., 1,000; j = 1, 2, ..., 10};
10,000 values for y denoted {y;jii = 1, 2, ..., 1,000; j = 1, 2,..., 10};
and 1,000 values for n denoted n1, n2,... , n1000-
Denote the output by myList. This output is used in the remaining parts of this question.
(c) Extract all the vectors with the name yVec. The result should be a list of 1000 vectors.
(d) Extract all the vectors with the name yVec. The result should be a 10 x 1000 matrix with one column
for each of the vectors yVec.
(e) Create a list which is identical to myList but all the components called count have been removed.
(f) Pick out those lists in myList which are such that count is greater than 2.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

Knowledge Booster
Similar questions
- Use Python for this question: Implement a function findMixedCase that accepts a single argument, a list of words, and returns the index of the first mixed case word in the list, if one exists, (a word is mixed case if it contains both upper and lower case letters), and returns -1 if the all words are either upper or lower case Output for this question is in the attached image:arrow_forwardcode should be python: write a function that allows the input of a list of strings as its only parameter. Inside the body of the function find the first palindromic word and return it. If there is no such word, it should return an empty string. A string is palindromic if it reads the same forward and backward so for example If we call the function with [“horse”, “rat”, “roar”, “dad”, “mom”], the returned value should be “dad”. Note that “mom” is also a palindrome, but it is not the first one.arrow_forward1. a.Palindromes Complete the function palindrome(String text). Return true if text is a palindrome; if the word is identical forward and backward. Otherwise, return false. Example: palindrome(“racecar”) == true palindrome(“kayaks”) == false See main() for more examples. You can use text.charAt(i) to find the character at index i of text. Use recursion. palindrome() should call itself. No loops allowed. b. Complete the function nestedBrackets(String s). This function should find properly nested brackets within s. Return true if brackets are opened and closed correctly, and false otherwise. Single pairs and nested pairs are valid. For example: z[z]z, [zz[zz]z], [z[[z]zzz]], zzzzz Incorrect pairings and multiple separate pairs are not valid. For example: zz[zz, ]zzz[, [zzz][z], [z[z][z]z] See main() for more examples. nestedBrackets() should call firstIndexOf() and lastIndexOf() to help you solve the problem. Use recursion. nestedBrackets() should call itself. No loops…arrow_forward
- Consider the following function shoots : def shoots(x: int) -> int: if x <= 0: return 0 4 elif x == 1: return shoots(x + 2) 6 elif x == 2: return shoots(x - 1) 80 elif x == 2: 9. return -1 10 else: 11 return shoots(x - 2) 2 3arrow_forwardProgram Assignment07implicit noneinteger, parameter :: n = 1000 ! maximum iterationreal(kind=8), parameter :: EPSILON = 1.d-3real(kind=8):: x0,xinteger:: iterationx0=3.0d0call solve(f(x),fp(x),x0,n,x,iteration) contains real (kind=8) function f(x) ! this is f(x)implicit nonereal (kind=8), intent(in)::xf=x**2.0d0-1.0d0end function f real (kind=8) function fp(x) ! This is f'(x)implicit nonereal (kind=8), intent(in)::xfp=2.0d0*xend function fp end program Assignment07 modify this program in fortran byy adding a module (called Newton) which contains subroutinesolve. You should develop subroutine solve based on the aforementioned Newton's method. ▪ Function f(x) is x2-1 whose zero is known. Set the input argument EPSILON to 1.E-3 and inputargument n to 1000 when you call subroutine solve and run the program Modify the function to one that is known not to have zeros; e.g. (x2+1)arrow_forwardFor input vector x, write a function to check whether there exists at most 5 elements in x whose values are less than 7.arrow_forward
- In Python, Compute the: sum of squares total (SST), sum of squares regression (SSR), sum of squares error(SSE), and the r, R^2 values. You can use the sum() and mean() built-in functions. Here are the x and y values to use. x = [-5,-1,3,7,5,10] y = [-10,-3,5,8,7,10]arrow_forwardcan anyone please solve this questions asap?arrow_forwardGiven a string containing only parentheses (, ), {, }, [, and ], determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Write a function isValidParentheses that takes in a string s and returns a boolean value indicating whether the parentheses in s are valid. Example: Input: s = "{[()]}" Output: true Input: s = "{[()]}" Output: false Input: s = "{[(])}" Output: false Input: s = "{[()]}()[]" Output: true Note: The input string will only contain the characters (, ), {, }, [, and ]. An empty string is considered valid.arrow_forward
- The MATLAB function arg supports variable arguments, returns the sum of the number of arguments and all arguments, and has a help function. Write the arg so that the next execution results. >> help argIt supports variable arguments. >> [n,m] = arg(5,6)n = 2m = 11>> [n, m] = arg(3,4,5)n = 3m = 12arrow_forwardvector, or a matrix in the same way as described for rand function. EXERCISE I8 Generate a random integer between I and 10. Ask user to guess the number. If user's guess is incorrect, ask' to guess again until user gets it right. At this point, tell user that he guessed it correctly and print out the number of attempts it took for the correct guess. Output Samples >> exercisel8 Please guess an integer between 1 and 10: 5 Your guess is incorrect. Please try again: 2 You guessed it correctly in 2 attemptS >> >> exercise16 Please guess an integer between 1 and 10: 2 Your guess is incorrect. Please try again: 3 Your guess is incorrect. Please try again: 6 Your guess is incorrect. Please try again: 5 Your guess is incorrect. Please try again: 8 Your guess is incorrect. Please try again: 9 Your guess is incorrect. Please try again: 10 Your guess is incorrect. Please try again: 1 Your guess is incorrect. Please try again: 4 Your guess is incorrect. Please try again: 7 You guessed it correctly…arrow_forwardpython help... Write a function justVowels() that takes a string as a parameter and returns a new string that contains all the vowels found in the parameter string. The vowels in the returned string should appear in the same order as they did in the parameter string. A vowel is one of a, e, i, o, or u. both the upper- and lower-case vowels should be included. The characters in the returned string should have the same capitalization as they did in the parameter string. If the function is given a string without any vowels or an empty string, it should return the empty string. Use the if-else condition with iterate loop pattern. Don’t forget to include the docstring and comments. How it should run... >>> justVowels('Did you include your collaboration statement') 'iouiueouoaoaioaee' >>> justVowels('If you did not include your collaboration statement no points') 'Iouioiueouoaoaioaeeooi' >>> justVowels('1,2,3,4,...') '' >>> justVowels('') ''arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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