Skip to content

Commit 82bda04

Browse files
ihazeihaze
authored andcommitted
finish the task
1 parent 7f657dd commit 82bda04

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

cachematrix.R

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
11
## Put comments here that give an overall description of what your
22
## functions do
3-
43
## Write a short comment describing this function
54

6-
makeCacheMatrix <- function(x = matrix()) {
5+
## ----------------------------------------- ##
6+
# 1. set the value of the vector
7+
# 2. get the value of the vector
8+
# 3. set the value of the mean
9+
# 4. get the value of the mean
10+
## ----------------------------------------- ##
711

12+
makeCacheMatrix <- function(x = matrix()) {
13+
14+
inverseMatrix <- NULL
15+
16+
set <- function(y) {
17+
x <<- y
18+
inverseMatrix <<- NULL
19+
}
20+
21+
get <- function() x
22+
setinverse <- function( inverse ) inverseMatrix <<- inverse
23+
getinverse <- function() inverseMatrix
24+
list( set = set,
25+
get = get,
26+
setinverse = setinverse,
27+
getinverse = getinverse)
828
}
929

1030

1131
## Write a short comment describing this function
1232

33+
## ----------------------------------------- ##
34+
# if it is possible solve inverse matrix
35+
## ----------------------------------------- ##
36+
1337
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
38+
39+
## Return a matrix that is the inverse of 'x'
40+
xmatrix <- x$getinverse()
41+
42+
if ( !is.null( xmatrix )) {
43+
message("getting cached data.")
44+
return( xmatrix )
45+
}
46+
47+
data <- x$get()
48+
xmatrix <- solve(data)
49+
50+
x$setinverse(xmatrix)
51+
xmatrix
1552
}
53+

0 commit comments

Comments
 (0)