Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
library(Biodem)
|
||||
m <- matrix(c(3,2,2,1), nrow=2)
|
||||
mtx.exp(m, 0)
|
||||
# [,1] [,2]
|
||||
# [1,] 1 0
|
||||
# [2,] 0 1
|
||||
mtx.exp(m, 1)
|
||||
# [,1] [,2]
|
||||
# [1,] 3 2
|
||||
# [2,] 2 1
|
||||
mtx.exp(m, 2)
|
||||
# [,1] [,2]
|
||||
# [1,] 13 8
|
||||
# [2,] 8 5
|
||||
mtx.exp(m, 3)
|
||||
# [,1] [,2]
|
||||
# [1,] 55 34
|
||||
# [2,] 34 21
|
||||
mtx.exp(m, 10)
|
||||
# [,1] [,2]
|
||||
# [1,] 1346269 832040
|
||||
# [2,] 832040 514229
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a <- matrix(c(1, 2, 3, 4), 2, 2)
|
||||
a^1
|
||||
a^2
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
`%^%` <- function(mat, n)
|
||||
{
|
||||
is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol#See the docs for is.integer
|
||||
if(is.matrix(mat) && is.numeric(n) && is.wholenumber(n))
|
||||
{
|
||||
if(n==0) diag(nrow = nrow(mat))#Identity matrix of mat's dimensions
|
||||
else if(n == 1) mat
|
||||
else if(n > 1) mat %*% (mat %^% (n - 1))
|
||||
else stop("Invalid n.")
|
||||
}
|
||||
else stop("Invalid input type.")
|
||||
}
|
||||
#For output:
|
||||
a %^% 0
|
||||
a %^% 1
|
||||
a %^% 2
|
||||
a %*% a %*% a#Base R's equivalent of a %^% 3
|
||||
a %^% 3
|
||||
nonSquareMatrix <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, ncol = 3)
|
||||
nonSquareMatrix %^% 1
|
||||
nonSquareMatrix %^% 2#R's %*% will throw the error for us
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
library(Biodem)
|
||||
`%^%` <- function(mat, n) Biodem::mtx.exp(mat, n)
|
||||
Loading…
Add table
Add a link
Reference in a new issue