Question

7. #4. 18 Following is a recursive function which takes as input (argument) a vector $x$ and returns a scalar. Either by look
0 0
Add a comment Improve this question Transcribed image text
Answer #1

c(1:1000) means, a vector of [1,2,3,...1000].

The given function describing the sum all elements in the given vector.

  • 1+ [2,3,4,....1000]
  • 3 + [3,4,5,.....1000]
  • 6 + [4,5,6,....1000]
  • ....

The answer is 500500 i.e the sum of [1,2,3.....1000]

The Modified code for calculating sum of exponential values of given vector

newfunction = function(x){
res = 0
for (val in x){
res = res + exp(val)
}
return(res)
}
newfunction(c(2,1,3,0,4))

Answer is 85.79102

Add a comment
Know the answer?
Add Answer to:
7. #4. 18 Following is a recursive function which takes as input (argument) a vector $x$...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 216#Question 5 - Bonus 217 def matrixMultiplication (matrix, vector): 218 219 220 221 """Return the product...

    216#Question 5 - Bonus 217 def matrixMultiplication (matrix, vector): 218 219 220 221 """Return the product of a matrix and a vector Arguments: matrix: A list of lists representing an nxn matrix vector: A list representing an nx1 matrix 223 224 225 226 227 228 229 230 231 232 233 234 Returns A list representing the nx1 matrix obtained by multiplying the input matrix by the input vector. >>> matrix = [[1, 2, 3], [2, 3, 1], [4, 1, >>>...

  • # 3. The following code draws a sample of size $n=30$ from a chi-square distribution with...

    # 3. The following code draws a sample of size $n=30$ from a chi-square distribution with 15 degrees of freedom, and then puts $B=200$ bootstrap samples into a matrix M. After that, the 'apply' function is used to calculate the median of each bootstrap sample, giving a bootstrap sample of 200 medians. "{r} set.seed (117888) data=rchisq(30,15) M=matrix(rep(0,30*200), byrow=T, ncol=30) for (i in 1:200 M[i,]=sample(data, 30, replace=T) bootstrapmedians=apply(M,1,median) (3a) Use the 'var' command to calculate the variance of the bootstrapped medians....

  • Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr,...

    Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example: >> A = randi(100,3,4) A = 66 94 75 18 4 68 40 71 85 76...

  • Write a function check palindrome, which takes a string x as argument and which returns True...

    Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....

  • Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as...

    Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...

  • 1. Write a Lisp function called piece which takes a single argument x and implements the followin...

    1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...

  • C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the r...

    C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything.     Your function should be named...

  • Download the hypothesis testing dataset from the class website. 1. This is case 1, in which...

    Download the hypothesis testing dataset from the class website. 1. This is case 1, in which the value of population standard deviation is assumed to be known. a. Compute the standard deviation of the textbook price and assume this to be the population standard deviation. Type this value in E5. b. Pick a random sample of size 15. c. Compute the mean of your random sample in E4 using the AVERAGE function. d. Calculate the standard error in cell E9...

  • 3. Write the function find sorted elt whose input is a vector sorted in increasing order...

    3. Write the function find sorted elt whose input is a vector sorted in increasing order and an element x. The output is 0 if the element x does not occur in v, 1 if the element x does occur in v. Below is the algorithm you should implement, known as the binary search algorithm. Note that the code below returns the index, but we want to return true or false, not the index, so adjust your code accordingly. Algorithm....

  • Paste BI Uv v Aviv X v fx 017 165) 166 The following table shows the...

    Paste BI Uv v Aviv X v fx 017 165) 166 The following table shows the demand curve in the schmoo market controlled by a single seller. Assume the 167 monopoly has no fixed costs and its marginal cost is constant at 54 per unit Complete the table by calculating total 168 revenue (TR) and marginal revenue (MR) Graph the demand curve, marginal revenue curve, marginal cost curve, and 169 the average cost curve in the graphing area provided following...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT