File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change 1
1
# # Put comments here that give an overall description of what your
2
2
# # functions do
3
3
4
+
4
5
# # Write a short comment describing this function
6
+ # makeCacheMatrix create an R object which calculates the matrix^-1 only once
5
7
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+ ix <- NULL
10
+ set <- function (mx ) {
11
+ x <<- mx
12
+ ix <<- NULL
13
+ }
14
+ get <- function (){
15
+ x
16
+ }
17
+ setinverse <- function (inverse ) {
18
+ ix <<- inverse
19
+ }
20
+ getinverse <- function () {
21
+ ix
22
+ }
23
+ list (set = set
24
+ , get = get
25
+ , setinverse = setinverse
26
+ , getinverse = getinverse )
8
27
}
9
28
10
29
11
- # # Write a short comment describing this function
12
-
30
+ # returns the inverse matrix from the object obtained from
31
+ # makeCacheMatrix calculating the value only once
13
32
cacheSolve <- function (x , ... ) {
14
33
# # Return a matrix that is the inverse of 'x'
34
+ i <- x $ getinverse()
35
+ if (! is.null(i )){
36
+ return (i )
37
+ }
38
+ mx <- x $ get()
39
+ i <- solve(mx , ... )
40
+ x $ setinverse(i )
41
+ i
15
42
}
43
+
You can’t perform that action at this time.
0 commit comments