Reputation: 35
*** It's related to R I want to take inverse of A (matrix) by inv(). Which package from what library should i install ?
Little code is as follows,
A <- matrix( c(5, 1, 0,
3,-1, 2,
4, 0,-1), nrow=3, byrow=TRUE)
det(A)
(AI <- inv(A))
Upvotes: 1
Views: 4830
Reputation: 2042
To get the inverse of a matrix in R, use the solve
function.
See https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/solve
A <- matrix( c(5, 1, 0,
3,-1, 2,
4, 0,-1), nrow=3, byrow=TRUE)
solve(A)
gives the output
[,1] [,2] [,3]
[1,] 0.0625 0.0625 0.125
[2,] 0.6875 -0.3125 -0.625
[3,] 0.2500 0.2500 -0.500
Upvotes: 4
Reputation: 1860
I typed "inv function r" into Google. First result was pracma
package:
library('pracma')
A <- matrix( c(5, 1, 0,
3,-1, 2,
4, 0,-1), nrow=3, byrow=TRUE)
det(A)
[1] 16
(AI <- inv(A))
[,1] [,2] [,3]
[1,] 0.0625 0.0625 0.125
[2,] 0.6875 -0.3125 -0.625
[3,] 0.2500 0.2500 -0.500
Upvotes: 1