Question

By using the R-Studio answer the following question: 1. a) write a simple loop to list...

By using the R-Studio answer the following question:

1. a) write a simple loop to list the squares of the first 10 integers.

b) Generate the 10*10 matrix A, whose (i;j) entry is sin(2*pi*(i-j))

Homework Answers

Answer #1

1

print("This loop calculates the square of the first 10 digits")

# Initialize usq

usq <- 0

for(i in 1:10) {

# i-th element of u1 squared into i`-th position of `usq

usq[i] <- i*i

print(usq[i])

}

2.

# Create a 10 x 10 matrix

mymat <- matrix(nrow=10, ncol=10)

# For each row and for each column, assign values based on position: product of two indexes

for(i in 1:dim(mymat)[1]) {

for(j in 1:dim(mymat)[2]) {

mymat[i,j] = sin(2*pi*(i-j))

}

}

# Just show the matrix

mymat[1:10, 1:10]

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use the data below to run a regression in R Studio and answer the following question....
Use the data below to run a regression in R Studio and answer the following question. You are given the following information about x and y. x                          y Independent    Dependent Variable            Variable 15                       5 12                       7 10                       9 7                         11 The least squares estimate of b1 equals _____. Group of answer choices a. 16.412 b. –0.13 c. 21.4 d. –0.7647
This problem requires using R studio. This question is from Verzani (Problem 2.15) Can some write...
This problem requires using R studio. This question is from Verzani (Problem 2.15) Can some write the code for the answer to the question below: The negation operator ! is used with reverse Boolean values. For example: A <- c(True, False, True, False) !A ##[1] False True False False One of De Morgan's laws in R code is ! (A & B) = !A | !B . Verify this with B <- c(False, True, False, True) and A as above.
This problem requires using R studio. This question is from Verzani (Problem 2.56) Can some write...
This problem requires using R studio. This question is from Verzani (Problem 2.56) Can some write the code for the answer to the question below: The Michelson(HistData) data set records 100 measurements by Michelson of the speed of light (in the variable velocity). Make a quantile-normal graph and discuss if the graphic shows the points falling on a straight line.
The following question can be answered in R code (using R-Studio or a program of your...
The following question can be answered in R code (using R-Studio or a program of your choice). Load the “star” data from the “faraway” package, and model “temp” using “light”. One may also suspect that the residuals (use all the data) follow a t distribution instead of normal. Using the same logic that we produced the QQ plot for comparing to the normal distribution, produce a QQ plot for comparing to a t distribution. You need to decide the degrees...
Using R or R-studio. 3. A fair coin is tossed until the first head occurs. Do...
Using R or R-studio. 3. A fair coin is tossed until the first head occurs. Do this experiment T = 10; 100; 1,000; 10,000 times in R, and plot the relative frequencies of this occurring at the ith toss, for suitable values of i. Compare this plot to the pmf that should govern such an experiment. Show that they converge as T increases. What is the expected number of tosses required? For each value of T, what is the sample...
Please do this in Matlab Using a single for-loop and no if-statements, write a code that...
Please do this in Matlab Using a single for-loop and no if-statements, write a code that will create a 10x10 matrix with 2 on the diagonal, and -1 on any entry right next to the diagonal.
Question #15. Write a function file that determines the following sum using a for loop: y=i=1n(3-2i)2...
Question #15. Write a function file that determines the following sum using a for loop: y=i=1n(3-2i)2 Use n as input and test the function for n=100. Question #15. Write a function file that determines the following sum using a for loop: y=i=1n(3-2i)2 Use n as input and test the function for n=100.
This problem requires using R studio. This question is from Verzani (Problem 6.25) Can some write...
This problem requires using R studio. This question is from Verzani (Problem 6.25) Can some write the code for the answer to the question below: A q-q plot is an excellent way to investigate whether a distribution is approximately normal. For the symmetric distributions Uniform (0,1), Normal (0,1), and t with 3 degrees of freedom, take a random sample of size 100 and plot a quantile-normal plot using qnorm. Compare the three and comment on the curve of the plot...
Please use R-studio code to answer the question! Create a variable called 'pizza' whose value corresponds...
Please use R-studio code to answer the question! Create a variable called 'pizza' whose value corresponds to the price of pizza you’ve eaten in the last week. Or something equally same. Now create another varible 'tax' whose value corresponds to 15% of the price of pizza. Now add these two values and store your result as 'myCost'. I assume the utility you enjoyed was 50 utils. So create a third variable 'myUtility' whose value is 50. Use logical operations to...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT