Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 500f18e

Browse files
committed
R programming assignment 2
1 parent 7f657dd commit 500f18e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

cachematrix.R

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
62
makeCacheMatrix <- function(x = matrix()) {
7-
3+
m<-NULL
4+
set<-function(y){
5+
x<<-y
6+
m<<-NULL
7+
}
8+
get<-function() x
9+
setmatrix<-function(solve) m<<- solve
10+
getmatrix<-function() m
11+
list(set=set, get=get,
12+
setmatrix=setmatrix,
13+
getmatrix=getmatrix)
814
}
915

10-
11-
## Write a short comment describing this function
12-
13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
16+
cacheSolve <- function(x=matrix(), ...) {
17+
m<-x$getmatrix()
18+
if(!is.null(m)){
19+
message("getting cached data")
20+
return(m)
21+
}
22+
matrix<-x$get()
23+
m<-solve(matrix, ...)
24+
x$setmatrix(m)
25+
m
1526
}

0 commit comments

Comments
 (0)