File tree Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Expand file tree Collapse file tree 1 file changed +30
-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
1
+ # Coursera programming assignment #2
2
+ # R Programming
3
+ # 20 AUG 2015
4
+ # This program takes an invertible matrix and creates a cached inverse of the input. The input can be
5
+ # retrieved by calling the second function. Subsequent calls will retrieve the inversed matrix from the cache
6
+ # rather than inversing the orginal input.
5
7
8
+ # makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse.
6
9
makeCacheMatrix <- function (x = matrix ()) {
7
-
10
+ f <- NULL
11
+ set <- function (y ) {
12
+ x <<- y
13
+ f <<- NULL
14
+ }
15
+ get <- function () x
16
+ setinverse <- function (solve ) f <<- solve
17
+ getinverse <- function () f
18
+ list (set = set , get = get ,
19
+ setinverse = setinverse ,
20
+ getinverse = getinverse )
8
21
}
9
22
10
23
11
- # # Write a short comment describing this function
12
-
24
+ # cacheSolve: This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
25
+ # If the inverse has already been calculated (and the matrix has not changed), then cacheSolve should
26
+ # retrieve the inverse from the cache.
13
27
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
28
+ f <- x $ getinverse()
29
+ if (! is.null(f )) {
30
+ message(" Getting the inversed matrix from the cache" )
31
+ return (f )
32
+ }
33
+ data <- x $ get()
34
+ f <- solve(data , ... )
35
+ x $ setinverse(f )
36
+ f
15
37
}
You can’t perform that action at this time.
0 commit comments