8000 Added files via upload · abdul-git/ProgrammingAssignment2@6f659a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f659a0

Browse files
committed
Added files via upload
1 parent cf6190a commit 6f659a0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

cachematrix.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
6+
##
7+
makeCacheMatrix <- function(x = matrix()) {
8+
## Holds the cache value or if nothing is cached
9+
cache <- NULL
10+
##seting matrix
11+
set <- function(y) {
12+
x <<- y
13+
cache <<- NULL
14+
}
15+
get <- function() {
16+
x
17+
}
18+
cacheInv <- function(solve) {
19+
cache <<- solve
20+
}
21+
getInv <- function() {
22+
cache
23+
}
24+
## get a list - naming fuction for each element of the list
25+
list(set = set, get = get, cacheInv = cacheInv, getInv = getInv)
26+
}
27+
28+
29+
## Write a short comment describing this function
30+
31+
## following function calculates the inverse of matrix created above "makeCacheMatrix"
32+
cacheSolve <- function(y, ...) {
33+
## get cache value if it is in cache
34+
inverse <- y$getInv()
35+
if(!is.null(inverse)) {
36+
## Display msg if data is cached!
37+
message("-- getting cached data --")
38+
return(inverse)
39+
}
40+
data <- y$get()
41+
inverse <- solve(data)
42+
y$cacheInv(inverse)
43+
inverse
44+
}
45+

0 commit comments

Comments
 (0)
0