File tree Expand file tree Collapse file tree 1 file changed +46
-9
lines changed Expand file tree Collapse file tree 1 file changed +46
-9
lines changed Original file line number Diff line number Diff line change 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
2
+ # # Function makeCacheMatrix
3
+ # #
4
+ # # Purpose:
5
+ # # Create a special "matrix" object that can cache its inverse.
6
+ # #
7
+ # # On Entry:
8
+ # # x - matrix
9
+ # #
10
+ # # One Exit:
11
+ # # returns an object that sotres a numeric vector and caches it inverse
12
+ # #
13
+ # #
6
14
makeCacheMatrix <- function (x = matrix ()) {
7
-
15
+ m <- NULL
16
+ set <- function (y ) {
17
+ x <<- y
18
+ m <<- NULL
19
+ }
20
+ get <- function () x
21
+ setinverse <- function (inverse ) m <<- inverse
22
+ getinverse <- function () m
23
+ list (set = set , get = get ,
24
+ setinverse = setinverse ,
25
+ getinverse = getinverse )
26
+
8
27
}
9
28
10
-
11
- # # Write a short comment describing this function
12
-
29
+ # # Function cacheSolve
30
+ # #
31
+ # # Purpose:
32
+ # # Computes the inverse of the special "matrix" returned by makeCacheMatrix.
33
+ # # If the inverse has already been calculated (and the matrix has not changed), then the cachesolve
34
+ # # should retrieve the inverse from the cache.
35
+ # #
36
+ # # On Entry:
37
+ # # Params: x matrix
38
+ # # '...' to pass through to solve
39
+ # # On Exit:
40
+ # # Returns a matrix that is the inverse of 'x'
41
+ # #
13
42
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
43
+ m <- x $ getinverse()
44
+ if (! is.null(m )) {
45
+ message(" getting cached data" )
46
+ return (m )
47
+ }
48
+ data <- x $ get()
49
+ m <- inverse(data , ... )
50
+ x $ setinverse(m )
51
+ m
15
52
}
You can’t perform that action at this time.
0 commit comments