Skip to content

Commit 62128f1

Browse files
committed
Updated file with functions as outlined in assignment
1 parent 7f657dd commit 62128f1

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

cachematrix.R

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
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.
57

8+
# makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse.
69
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)
821
}
922

1023

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.
1327
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
1537
}

0 commit comments

Comments
 (0)