Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Employ effective vocal cues Employ effective visual cues

Answered: 1 week ago