Computers and Technology
Computers and Technology, 08.07.2020 01:01, kivking12

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)

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:00, jcastronakaya
Apex q: what does a low employment rate indicate? a. not many people are earning high salaries b. not many people are going to college c. not many people are renting their homes d. not many people have jobs
Answers: 2
image
Computers and Technology, 22.06.2019 10:30, ilovepickles930
What can tanya do now to start preparing for the college and scholarship application process? think about her grades, activities in which she can get involved, possible part-time jobs at which she can work, and standardized tests she can take. (10 points) apex
Answers: 2
image
Computers and Technology, 23.06.2019 10:00, serenityharmon1
Hey i just logged on and one of the moderators deleted a bunch of my answers to questions, even though the answers were right and the people it doesn't make sense but if anyone wants to talk about anything just message me lol (this is super random lol)
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, ryleerose255
Idon’t understand the double8 coding problem. it is java
Answers: 1
Do you know the correct answer?
Let's get into some looping. Sometimes it is nice to generate your own data. Now let's take our firs...

Questions in other subjects: