forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
32 lines (32 loc) · 1.01 KB
/
cachematrix.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# calling makecachematrix() function
# return value ( a list of four functions) to a variable,m
# m is now a list of four functions
makeCacheMatrix <- function (x = matrix()) {
I <- NULL
# use v's set function to create a matrix with nrow =n and nrow =n
set <- function(y = matrix()) {
x <<- y
I <<- NULL
# use v's get function to retrieve the matrix created and pass the created matrix v to the cacheSolve() function
# the inverse of the matrix will be returned
}
get <- function() x
setsolve <- function(solve) I <<- solve(x)
getsolve <- function() I
result <- list(set = set, get = get ,
setsolve = setsolve ,
getsolve = getsolve)
return(result)
}
cacheSolve <- function(x) {
I <- x$getsolve()
if(!is.null(I)) {
# Retrieving inverse matrix a second time from the environment without performing any calculation
message( "retrieving catched inverse matrix")
return(I)
}
data <- x$get()
I <- solve(data)
x$setsolve(I)
I
}