File tree Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Original file line number Diff line number Diff line change 1+ # #setwd("C:/Users/eduardo/Documents/GitHub/ProgrammingAssignment2")
12# # Put comments here that give an overall description of what your
23# # functions do
34
45# # Write a short comment describing this function
56
67makeCacheMatrix <- function (x = matrix ()) {
8+ d <- dim(x )
9+ if (d [1 ] != d [2 ]) {
10+ stop(" The matrix has to be square" )
11+ }
712
13+ # # matrix of inverse
14+ i <- NULL
15+
16+ # # set matrix
17+ set <- function (y ) {
18+ x <<- y
19+ i <<- NULL
20+ }
21+
22+ # # get matrix
23+ get <- function () x
24+
25+ # # set matrix of inverse
26+ setmi <- function (matrix ) i <<- matrix
27+
28+ # # get matrix of inverse
29+ getmi <- function () i
30+
31+
32+ list (set = set , get = get ,
33+ setmi = setmi ,
34+ getmi = getmi )
35+
836}
937
10-
1138# # Write a short comment describing this function
1239
1340cacheSolve <- function (x , ... ) {
41+
42+ i <- x $ getmi()
43+ if (! is.null(i )) {
44+ message(" getting cached data" )
45+ return (i )
46+ }
47+
48+ matrix <- x $ get()
49+ i <- solve(matrix )
50+ x $ setmi(i )
51+
1452 # # Return a matrix that is the inverse of 'x'
15- }
53+ i
54+ }
55+
You can’t perform that action at this time.
0 commit comments