File tree Expand file tree Collapse file tree 1 file changed +33
-12
lines changed Expand file tree Collapse file tree 1 file changed +33
-12
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
+ # # Create a function called makeCacheMatrix
2
+ # # Set values of the matrix
6
3
makeCacheMatrix <- function (x = matrix ()) {
7
-
4
+ m <- NULL
5
+ set <- function (y ){
6
+ x <<- y
7
+ m <<- NULL
8
+ }
9
+ # # gets the fuction & returns x ie the matrix
10
+ get <- function () x
11
+ # # sets the value of the inverse Matrix
12
+ setinverse <- function (solve ) m <<- solve
13
+ # # gets the value of the inverse matrix
14
+ getinverse <- function () m
15
+ list (set = set , get = get ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
8
18
}
9
-
10
-
11
- # # Write a short comment describing this function
12
-
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
19
+ # # Create a function called cacheSolve
20
+ cacheSolve <- function (x = matrix (), ... ) {
21
+ # # Checks to see if values of inverse already exists in the
22
+ # # environment
23
+ m <- x $ getinverse()
24
+ # # If the inverse DOES exist then returns cached value
25
+ if (! is.null(m )){
26
+ message(" getting cached data" )
27
+ return (m )
28
+ }
29
+ # #If the inverse DOES NOT then calculates and stores
30
+ # # the inverse matrix
31
+ matrix <- x $ get()
32
+ m <- solve(matrix , ... )
33
+ x $ setinverse(m )
34
+ m
15
35
}
36
+
You can’t perform that action at this time.
0 commit comments