File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do 
1+ # # Put comments here that give an overall description of what your functions do 
2+ # # These  functions create a special "matrix" object that can cache its inverse. 
33
44# # Write a short comment describing this function
5- 
5+ # # This function creates a special "matrix" object that can cache its inverse. 
66makeCacheMatrix  <-  function (x  =  matrix ()) {
7- 
7+   inv  <-  NULL 
8+   set  <-  function (y ) {
9+     x  <<-  y 
10+     inv  <<-  NULL 
11+   }
12+   get  <-  function () x 
13+   setinverse  <-  function (inverse ) inv  <<-  inverse 
14+   getinverse  <-  function () inv 
15+   list (set  =  set , get  =  get ,
16+        setinverse  =  setinverse ,
17+        getinverse  =  getinverse )
818}
919
10- 
1120# # Write a short comment describing this function
12- 
21+ # # This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
22+ # # If the inverse has already been calculated (and the matrix has not changed),
23+ # # then cacheSolve should retrieve the inverse from the cache.
1324cacheSolve  <-  function (x , ... ) {
14-         # # Return a matrix that is the inverse of 'x'
25+   inv  <-  x $ getinverse()
26+   if  (! is.null(inv )) {
27+     message(" getting cached data" 
28+     return (inv )
29+   }
30+   mat  <-  x $ get()
31+   inv  <-  solve(mat , ... )
32+   x $ setinverse(inv )
33+   inv 
1534}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments