Skip to content

Commit aeaf016

Browse files
committed
solution to the assignment
1 parent 7f657dd commit aeaf016

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
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

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: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
1+
## makeCacheMatrix creates a list of functions used to
2+
## 1. set the value of the matrix
3+
## 2. get the value of the matrix
4+
## 3. set the value of the inverse matrix
5+
## 4. get the value of the inverse matrix
66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
i <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
i <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inv) i <<- inv
14+
getinverse <- function() i
15+
list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
816
}
917

1018

11-
## Write a short comment describing this function
12-
19+
## cacheSolve calculates the inverse of x and caches the result
20+
## calling this function will return the cached result if called more than once
1321
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
22+
i <- x$getinverse()
23+
if (!is.null(i)) {
24+
return(i)
25+
}
26+
data <- x$get()
27+
i <- solve(data, ...)
28+
x$setinverse(i)
29+
i
1530
}

0 commit comments

Comments
 (0)