-## Put comments here that give an overall description of what your
-## functions do
-
+## makeCacheMatrix creating matrix by input matrix can be inversed
+##it return to a list contains 4 functions
+#get()output the matrix stored in x
+#setinv()pass the inverse to variable define in upper environment
 ## Write a short comment describing this function

 makeCacheMatrix <- function(x = matrix()) {
-
+  inv<-NULL
+  set <-function(y=matrix()) {
+    x <<- y
+    inv <<- NULL
+  }
+  get <- function() x
+  setinv <- function(solve) inv <<- solve
+  #store the inv passed by setinv in upper environment
+  getinv <- function() inv
+  list(set = set, get = get,
+       setinv = setinv,
+       getinv = getinv)
 }

-
-## Write a short comment describing this function
+##calculate inverse of x and store it in function and pass it

 cacheSolve <- function(x, ...) {
+  inv<- x$getinv()
+  inv <- inv
+  if(!is.null(inv)) {
+      message("getting cached data")
+      return(inv)
+                  }
+  data <- x$get()
+  inv <- solve(data, ...)
+  x$setinv(inv)#this inv is one defined in cacheSolve not before
+  inv
         ## Return a matrix that is the inverse of 'x'
 }