forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
37 lines (30 loc) · 966 Bytes
/
cachematrix.R
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
## makeCacheMatrix is makes a special matrix object which has four functions
##cacheMatrix checks if its inverse is already cslculated if not
##it calculates and stores it in matrix object
## Write a short comment describing this function
##set(matrix):sets x to y and inverse as null because it needs to be calculated
##get(): reurn matrix
##setInverse(solve):sets solve to I solve being inverse of x
##getInverse():returns inverse
makeCacheMatrix <- function(x = matrix()) {
I<-NULL
set=function(y){x<<-y
I<<-NULL
}
get=function()x
setInverse=function(solve)I<<-solve
getInverse=function()I
list(set=set,get=get,setInverse=setInverse,getInverse=getInverse)
}
## Write a short comment describing this function
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m=x$getInverse()
if(!is.na(m)){
return(m)
}
mat=x$get()
In=solve(mat)
x$setInverse(In)
In
}