FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ProgrammingAssignment2/cachematrix.R at master · EPBaron/ProgrammingAssignment2 · GitHub
EPBaron
/
ProgrammingAssignment2
Public
forked from
rdpeng/ProgrammingAssignment2
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ProgrammingAssignment2
/
cachematrix.R
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (44 loc) · 1.45 KB
Breadcrumbs
ProgrammingAssignment2
/
cachematrix.R
Copy path
File metadata and controls
54 lines (44 loc) · 1.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
# Function to create a special matrix vector which
#
# returns a list of 4 functions:
#
# 1) set the value of the matrix
#
# 2) get the value of the matrix
#
# 3) set the value of the inverse
#
# 4) get the value of the inverse
makeCacheMatrix
<-
function
(
x
=
matrix
()) {
#
initialize inverse to NULL
inverse
<-
NULL
#
1) set the value of the matrix
set
<-
function
(
y
) {
x
<<-
y
#
NULL inverse variable since matrix is new
inverse
<<-
NULL
}
#
2) get the value of the matrix
get
<-
function
()
x
#
3) set the value of the inverse
setInverse
<-
function
(
inverse
)
inverse
<<-
inverse
#
4) get the value of the inverse
getInverse
<-
function
()
inverse
#
return a vector of functions 1-4
list
(
set
=
set
,
get
=
get
,
setInverse
=
setInverse
,
getInverse
=
getInverse
)
}
#
# Function to calculate the inverse of the special matrix
#
# created with the makeCacheMatrix function above.
cacheSolve
<-
function
(
x
,
...
) {
#
first check to see if the inverse has already been calculated
inverse
<-
x
$
getInverse()
if
(
!
is.null(
inverse
)) {
message(
"
getting cached data
"
)
return
(
inverse
)
}
#
since inverse not cached, read matrix into local variable
data
<-
x
$
get()
#
compute inverse of matrix
inverse
<-
solve(
data
,
...
)
#
cache the inverse for future lookups
x
$
setInverse(
inverse
)
#
return the value of matrix inverse
inverse
}
Back
|
FazBrowse Home
|
New Git URL