Tiffany Nguyen
Tiffany Nguyen

Reputation: 19

How would I generate 1000 2x2 matrices whose elements are random numbers?

How would I do this in R? The prompt is:

Generate 1000 2⇥2 matrices whose elements are random numbers(not all integers) that range between 10 and 10.2.For each matrix compute the eigenvalues. Plot each eigenvalue

So far I've done M=matrix(runif(4, min=-10, max=10), ncol=2, nrow=-10)

and I don't really know where to go from here.

Upvotes: 0

Views: 227

Answers (1)

akash87
akash87

Reputation: 3994

Not sure if you want this as a list, but if you do:

mats <- lapply(1:1000, function(x) matrix(runif(4), ncol = 2, nrow = 2))
eigens <- lapply(mats, eigen)

Upvotes: 0

Related Questions