Skip to content

Commit

Permalink
Assignment2
Browse files Browse the repository at this point in the history
Assignment2
  • Loading branch information
pim61sit committed Jun 11, 2022
1 parent 7f657dd commit 7a67af0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Binary file added .DS_Store
Binary file not shown.
36 changes: 31 additions & 5 deletions cachematrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,40 @@
## functions do

## Write a short comment describing this function

makeCacheMatrix <- function(x = matrix()) {

library(MASS)
makeCacheMatrix <- function(x = matrix(x = matrix())) {
inv<-NULL
set<-function(y){
x<<-y
inv<<-NULL
get<-function()x
setinv<-function(inverse)inv<<-inverse
getinv<-function(){
inver<-ginv(x)
inver%*%x
}
list(set = set, get = get,
setinv = setinv,
getinv = getinv)
}
}


## Write a short comment describing this function

cacheSolve <- function(x, ...) {
cacheSolve <- function(x, ...)
{
inv<-x$getinv()
if(!is.null(inv)){
message("getting cached data!")
return(inv)
}
data<-x$setinv()
inv<-solve(data,...)
x$setinv(inv)
inv
## Return a matrix that is the inverse of 'x'
}

f<-makeCacheMatrix(matrix(1:8,2,4))
f$get()
cacheSolve(f)

0 comments on commit 7a67af0

Please sign in to comment.