-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramming Assignment 2: Lexical Scoping
More file actions
54 lines (46 loc) · 1.06 KB
/
Programming Assignment 2: Lexical Scoping
File metadata and controls
54 lines (46 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
cacheMatrix <- function(x = matrix()) {
m<-NULL
#--- set_matrix the matrix ---
set_matrix<-function()
{
x<<-y
m<<-NULL
}
# --- get the matrix ----
get <- function()
{
x
}
#--- set_matrix the inverse of the matrix----
set_matrixInverse <- function(inverse)
{
i <<- inverse
}
#---get the inverse of the matrix ----
getInverse <- function()
{
m
}
#-- Return list of methods ---
list(set_matrix = set_matrix, get = get,
set_matrixInverse = set_matrixInverse,
getInverse = getInverse)
}
##function for cacheing the inverse of a matrix
cacheSolve <- function(x, ...) {
m <- x$getInverse()
#--- if inverse is set already, return it ---
if( !is.null(m) )
{
message("getting cached data_input")
return(m)
}
#--- Get the matrix from our object ---
data_input <- x$get()
#--- inverse calculation using matrix multiplication ---
m <- solve(data_input) %*% data_input
#--- set_matrix the inverse to the object ---
x$set_matrixInverse(m)
#--- Return the matrix---
m
}