Skip to content

Commit 664a5af

Browse files
committed
my solution to Programming Assignment 2
1 parent 7f657dd commit 664a5af

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

cachematrix.R

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
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
63
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)
818
}
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
1535
}
36+

0 commit comments

Comments
 (0)