Skip to content

Commit 646a7ff

Browse files
committed
1 parent 7f657dd commit 646a7ff

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

ProgrammingAssignment2.Rproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX

cachematrix.R

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
1+
## at first we create a special "matrix" object that can cache its inverse
52

63
makeCacheMatrix <- function(x = matrix()) {
7-
4+
inv <- NULL
5+
set <- function(y){
6+
x <<- y
7+
inv <<- NULL
8+
}
9+
get <- function() x
10+
setInverse <- function(solveMatrix) inv <<- solveMatrix
11+
getInverse <- function() inv
12+
list(set = set, get = get,
13+
setInverse = setInverse,
14+
getInverse = getInverse)
815
}
916

1017

11-
## Write a short comment describing this function
18+
## This function computes the inverse of the special "matrix" if it's not available in cache
1219

1320
cacheSolve <- function(x, ...) {
1421
## Return a matrix that is the inverse of 'x'
22+
inv <- x$getInverse()
23+
if(!is.null(inv)){
24+
message("getting data from cache")
25+
return(inv)
26+
}
27+
data <- x$get()
28+
inv <- solve(data)
29+
x$setInverse(inv)
30+
inv
1531
}

0 commit comments

Comments
 (0)