This week went very smoothly, working with matrices and doing some simple algebra with them. These are all built in function in R, most of which I had seen. I made up my own matrix values, as those suggested to use on Canvas do not work (since 6 does not divide evenly into 100 or 1000).
> A <- matrix(runif(100,1, 400), nrow = 10, ncol = 10)
> B <- matrix(runif(2500, 1, 500), nrow = 50, ncol = 50)
Taking the inverse requires only 1 letter...
> t(A)
The output will not format well in here, so I will skip pasting that in, calling t(B) returns the inverse for matrix B.
Determinants are easy as well, the same idea as a transverse;
> det(A)
[1] -8.837604e+23
> det(B)
[1] 8.667763e+139
The inverse calls a rather odd function called "solve". It seems to do a lot. I will have to explore it more to get a better feel for it.
> solve(A)
Again, this is a large output which will not appear well here.
Multiplying a matrix by a vector is also as simple as any other multiplication. First we need a vector with the same number of columns:
> a <- c(seq(11,20,1)
> a*A
> a*B
still works, even though "a" has 10 values and B has 50 columns. R will automatically loop the "a" vector to match the size of the "B" matrix.
That looks like all the calculation needed of us this week. Off to learn more about "solve"!
No comments:
Post a Comment