subject

Let's get into some looping. Sometimes it is nice to generate your own data. Now let's take our first stab at it. (a) Lets start simple by just making a counter. Write a loop that just prints the numbers 1 through 5. To do this, first define an object counter outside of the loop. Set it equal to zero. Inside the loop use the print() command. It will simply print whatever is inside the brackets.
(b) Now lets use that counter. Make a loop that creates a vector, where the first element is 1, second element is 2, ..., the fifth element is 5: [1 2 3 4 5] Stat by making a blank vector so that you can fill it. I always start with a vector full of weird number. For example you could use -999. That way, if something is wrong in your data, you will be able to pick it out right away. After you create this container, you will fill it in the loop.
(c) Lets create a vector of random numbers, all of which come from a normal distribution with a different mean. To do this, we will use the rnorm() command. Look up the help file for this command. The argument n tells it how many numbers to draw. The argument mean tells it what the mean of the distribution is. The argument sd tells it what the standard deviation of the distribution is. Make a vector where there are 5 elements. The first element should be drawn from a distri- bution with a mean of 3, the second from a distribution with a mean of 7, the third from a distribution with a mean of 4, the fourth from a distribution with a mean of 10, and the fifth from a distribution with a mean of 2. To do this you will need to specify a vector as your list in the for command.
(d) Now we're going to do something a bit more difficult. I want you to recreate the first 10 numbers in the Fibonacci sequence. To do this, you will again need to create a container vector. Then you will need to feed it the first two numbers in the sequence outside of the loop. Then, you will need to fill the rest of the sequence by using the loop. (Hint: You can create counters inside of the loop to help pick out elements that are already in the matrix)

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:30
Consider the following statements: #include #include class temporary { private: string description; double first; double second; public: temporary(string = "", double = 0.0, double = 0.0); void set(string, double, double); double manipulate(); void get(string& , double& , double& ); void setdescription(string); void setfirst(double); void setsecond(double); }; write the definition of the member function set() so that the instance variables are set according to the parameters. write the definition of the constructor so that it initializes the instance variables using the function set() write the definition of the member function manipulate() that returns a decimal number (double) as follows: if the value of description is "rectangle", it returns first * second if the value of description is "circle" it returns the area of a circle with radius first if the value of description is "cylinder" it returns the volume of a cylinder with radius first and height second. hint: the volume of a cylinder is simply the area of the circle at the base times the height. if the value of description is "sphere" it returns the volume of the sphere with radius first. otherwise it returns -1.0;
Answers: 1
question
Computers and Technology, 23.06.2019 23:00
Computer programming is one type of what career
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Into what form does the barcode reader convert individual bar patterns?
Answers: 1
question
Computers and Technology, 24.06.2019 16:00
To fill (copy) a cell across or down, point to the of the cell and drag. top left corner top right corner bottom left corner bottom right corner
Answers: 3
You know the right answer?
Let's get into some looping. Sometimes it is nice to generate your own data. Now let's take our firs...
Questions
question
Chemistry, 22.09.2019 05:30
Questions on the website: 13722363