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

Skip to content

Commit ca50649

Browse files
committed
completed assignment - before testing.
1 parent 7f657dd commit ca50649

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-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

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: 4
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX

cachematrix.R

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## These functions provide a way to create an inverted matrix, and everytime
2+
## thereafter return a cached version of the matrix until another
3+
## matrix is inverted.
34

4-
## Write a short comment describing this function
5+
## This function provides access to set and get a cached version of a matrix.
56

67
makeCacheMatrix <- function(x = matrix()) {
7-
8+
im <- NULL
9+
set <- function(y) {
10+
x <<- y
11+
im <<- NULL
12+
}
13+
get <- function() x
14+
setsolve <- function(inMatrix) im <<- inMatrix
15+
getsolve <- function() im
16+
list(set = set, get = get,
17+
setsolve = setsolve,
18+
getsolve = getsolve)
819
}
920

1021

11-
## Write a short comment describing this function
22+
## This function returns an inverse of the matrix given to the makeCacheMatrix
23+
## function. If the matrix has already been inverted and cached, it will return
24+
## the cached version, otherwise, it will invert and then cache the matrix.
1225

1326
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
27+
m <- x$getsolve()
28+
if(!is.null(m)) {
29+
message("getting cached matrix")
30+
return(m)
31+
}
32+
data <- x$get()
33+
m <- solve(data, ...)
34+
x$setsolve(m)
35+
m
1536
}

0 commit comments

Comments
 (0)