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 12:10
Linux is distributed under gnu gpl. why is this important? a. it ensures that only torvalds can profit from the sale of linux b. it prevents unknowledgeable users from downloading programs they don't know how to operate. c. it provides protection for the developers who created linux. d. it states that anyone can copy, modify, and share the program if changes are made public.
Answers: 1
question
Computers and Technology, 22.06.2019 19:00
Which parts of a presentation should be the most general? a. introduction and conclusion b. introduction and outline c. outline and conclusion d. outline and body
Answers: 1
question
Computers and Technology, 23.06.2019 10:00
What is estimated time of arrival (eta)? a device that measures the acceleration (the rate of change of velocity) of an item and is used to track truck speeds or taxi cab speeds a gps technology adventure game that posts the longitude and latitude location for an item on the internet for users to find a north/south measurement of position the time of day of an expected arrival at a certain destination and is typically used for navigation applications
Answers: 3
question
Computers and Technology, 23.06.2019 10:50
Your friend kayla is starting her own business and asks you whether she should set it up as a p2p network or as a client-server network. list three questions you might ask to kayla decide which network to use and how her answers to those questions would affect your recommendation.
Answers: 2
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
History, 22.04.2021 18:30
question
Spanish, 22.04.2021 18:30
question
Mathematics, 22.04.2021 18:30
question
Mathematics, 22.04.2021 18:30
question
Mathematics, 22.04.2021 18:30
Questions on the website: 13722361