forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpruebadel9.R
More file actions
34 lines (26 loc) · 1.07 KB
/
pruebadel9.R
File metadata and controls
34 lines (26 loc) · 1.07 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
## Small function to check the results of cachematrix.R functions
##
## nf: number of rows and columns of the matrix used to test the functions
pruebadel9<-function(nf=10){
## Fill the matrix with rnorm
xMatrix<-matrix(rnorm(nf*nf),nrow=nf,ncol=nf)
## Initialize xCache
xCache<-makeCacheMatrix(xMatrix)
## First call to cacheSolve. Compute the inverse.
message("\nfirst call to cacheSolve")
print(cacheSolve(xCache))
## Second call to cacheSolve. Gets the inverse from the cache.
message("\nsecond call to cacheSolve")
print(cacheSolve(xCache))
## function to "clean" the matrix of very small numbers using sapply
ff<-function(x){
if(abs(x)<1.e-6)
0
else
x
}
## the product of the matrix with its inverse should result the unity matrix
## clean the resulting matrix for readability
message("\nunity matrix")
matrix(sapply(xCache$get()%*%xCache$getinv(),ff),nrow=nf,ncol=nf)
}