8000 Completed assignment #2 · pedrokost/ProgrammingAssignment2@f726c05 · GitHub
[go: up one dir, main page]

Skip to content

Commit f726c05

Browse files
committed
Completed assignment rdpeng#2
1 parent 7f657dd commit f726c05

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData

RProgrammingAssignment2.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
1+
## makeCacheMatrix and cacheSolve are a pair of functions that
2+
## allow efficient repeated computation of a matrix inverse
33

4-
## Write a short comment describing this function
4+
## Returns a special matrix that is able to cache its inverse
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
inv <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
inv <<- NULL
11+
}
12+
get <- function() x
13+
setinv <- function(inverse) inv <<- inverse
14+
getinv <- function() inv
15+
list(set=set, get=get, setinv=setinv, getinv=getinv)
816
}
917

1018

11-
## Write a short comment describing this function
19+
## Returns the inverse of a spacial matrix
1220

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

0 commit comments

Comments
 (0)
0