File tree Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Expand file tree Collapse file tree 1 file changed +29
-8
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
+ # # The first function, makeCacheMatrix creates a special "matrix",
2
+ # # which is really a list containing a function to:
3
+ # # set the value of the matrix
4
+ # # get the value of the matrix
5
+ # # set the value of the inverse matrix
6
+ # # get the value of the inverse matrix
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ im <- NULL
9
+ set <- function (y ) {
10
+ x <<- y
11
+ inverseMatrix <<- NULL
12
+ }
13
+ get <- function () x
14
+ setinverse <- function (inverseMatrix ) im <<- inverseMatrix
15
+ getinverse <- function () im
16
+ list (set = set , get = get ,
17
+ setinverse = setinverse ,
18
+ getinverse = getinverse )
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # The second function calulates inverse matrix, that is stored
23
+ # # in object function above, or returns cached inverse of the matrix
12
24
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ # # Return a matrix that is the inverse of 'x'
27
+ im <- x $ getinverse()
28
+ if (! is.null(im )) {
29
+ message(" getting cached matrix" )
30
+ return (im )
31
+ }
32
+ data <- x $ get()
33
+ im <- solve(data )
34
+ x $ setinverse(im )
35
+ im
15
36
}
You can’t perform that action at this time.
0 commit comments