Question: A . Write a for loop that computes the product of all odd numbers from 1 to 5 1 . At the end of the

A. Write a for loop that computes the product of all odd numbers from 1 to 51. At the end of the loop, your code should produce the final message "The product of all odd numbers between 1 and 51 is x", where x is your answer.
B. Write a for loop that counts the number of negative numbers in a list of 5000 random numbers between -1 and 1, generated by the runif command. Use an if/else command in the loop to count "+1" when number is negative and does not count if the number is nonnegative.
Your code for this part should end with the text "The number of negative numbers is Z", where Z is the number of negative numbers.
C. Repeat the previous step, except compute the number of negative numbers in 2000 randomly generated vectors, each of which contains 5000
numbers. As part of this process your code should create a vector with 2000 elements, each of which is the # of negative numbers in one of
the randomly generated 5000-element vectors. Use the mean command to find the average number of negative numbers in the 2000 vectors.
Your code should end with the sentence "The average number of negative numbers in the 2000 random vectors is Z", where Z is the average. You will need a for loop outside of the for loop
from the previous step. This is called a nested for loop. What number is closest to your average? Is it what you expected?
D.R allows for a much faster way to count the number of elements ina vector that satisfy a certain condition. If myvector is your 5000
element vector of random numbers, the command sum (myvector 0) will count the number of elements less than 0. Use this fact to modify your code from the previous step so that you only use ONE for loop. But this time, generate 10000 random vectors, each with 10000 elements. Assign the name numnegs to the 10000 element vector that contains the number of negative numbers found in each of the 10000 randomly generated vectors of 10000 numbers between -1 and 1.
 A. Write a for loop that computes the product of all

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!