Skip to content

Commit cb2b668

Browse files
committed
Revisions#1
Revisions made to stub files by student SGC
1 parent 7f657dd commit cb2b668

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

cachematrix.R

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
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-
6-
makeCacheMatrix <- function(x = matrix()) {
1+
## code source: desktop>coursera>ProgrammingAssignment2>cachematrix.R
2+
## programmer: SGC, Raleigh,NC
73

4+
## Function creates a sepcial matrix which
5+
## * Sets the value of the matrix
6+
## Gets the value of the matrix
7+
## Sets the value of the matrix inverse
8+
## Gets the value of the matrix inverse
9+
makeCasheMatrix <- function(x = matrix()) {
10+
m <- NULL
11+
set <- function(y) {
12+
x <<- y
13+
m <<- NULL
14+
}
15+
get <- function() x
16+
setsolve <- function(solve) m <<- solve
17+
getsolve <- function() m
18+
matrix(set = set, get = get,
19+
setsolve = setsolve,
20+
getsolve = getsolve)
821
}
922

1023

11-
## Write a short comment describing this function
24+
##The following function calculates the inverse of the special "matrix"
25+
##created with the above function. However, it first checks to see
26+
##if the inverse has already been calculated. If so, it gets the inverse
27+
##from the cache and skips the computation. Otherwise, it calculates
28+
##the inverse of the data matrix and
29+
##sets the value of the inverse in the cache via the setsolve function.
30+
1231

1332
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
15-
}
33+
m <- x$getsolve()
34+
if(!is.null(m)) {
35+
message("getting cached data")
36+
return(m)
37+
}
38+
data <- x$get()
39+
m <- solve(data, ...)
40+
x$setsolve(m)
41+
m
42+
}

0 commit comments

Comments
 (0)