forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachematrix.R
More file actions
33 lines (27 loc) · 865 Bytes
/
Copy pathcachematrix.R
File metadata and controls
33 lines (27 loc) · 865 Bytes
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
## This 2 by 2 matrix generates random number based on a given value of x, which represents the mean of a normal distribution
## This creates a matrix. Make sure to assign a value of X (ie. x = 5) before performing the analysis
makeCacheMatrix = function() {
x = matrix(rnorm(4,x),2,2)
set = function(h) h <<- x
inverse = NULL
get = function() x
i = NULL
setinverse = function(i) i <<- solve(x)
getinverse = function() i
list (set = set, get = get, setinverse = setinverse, getinverse = getinverse)
}
## This solves for the inverse
cacheSolve = function(x) {
Answer = x$getinverse()
if (!is.null(Answer)) {
message("getting cached data")
return(Answer)
} else {
data = x$get ()
j = solve(data)
x$setinverse(j)
j
}
}
git config --global user.email "kenneth_leng@u.nus.edu"
git config --global user.name "Kenneth"