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))
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]
Get Answers For Free
Most questions answered within 1 hours.