Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (37 loc) · 1.4 KB

File metadata and controls

42 lines (37 loc) · 1.4 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
36
37
38
39
40
41
# Matrix inversion is usually a costly computation so it's a good idea to
# cache the inverse of a matrix rather than compute it repeatedly. The
# following two functions are used to cache the inverse of a matrix.
# makeCacheMatrix creates a list containing functions which
# (a) set the value of the matrix
# (b) get the value of the matrix
# (c) set the value of inverse of the matrix
# (d) get the value of inverse of the matrix
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
set <- function(y) {
x <<- y
m <<- NULL
}
get <- function() x
setsolveMatrix <- function(solve) m <<- solve
getsolveMatrix <- function() m
list(set = set, get = get,
setsolveMatrix = setsolveMatrix,
getsolveMatrix = getsolveMatrix)
}
# The following function returns the inverse of the matrix. Firstly, it checks if
# the inverse has already been computed. If so, it gets the result and skips the
# computation. If not, it computes the inverse. It sets the value in the cache via
# the setsolveMatrix function.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getsolveMatrix()
if(!is.null(m)) {
message("getting cached data")
return(m)
}
data <- x$get()
m <- solve(data)
x$setsolveMatrix(m)
m
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.