SCM

SCM Repository

[matrix] Annotation of /pkg/tests/matr-exp.R
ViewVC logotype

Annotation of /pkg/tests/matr-exp.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 521 - (view) (download)

1 : maechler 519 ## Matrix Exponential
2 :    
3 :     assert.EQ.mat <- function(M, m, tol = 1e-15)
4 :     stopifnot(all.equal(as(M, "matrix"), m, tol = tol))
5 :    
6 :    
7 :     m1 <- Matrix(c(1,0,1,1), nc = 2)
8 :     e1 <- expm(m1)
9 : maechler 521 assert.EQ.mat(e1, cbind(c(exp(1),0), exp(1)))
10 : maechler 519
11 :     m2 <- Matrix(c(-49, -64, 24, 31), nc = 2)
12 :     e2 <- expm(m2)
13 :     assert.EQ.mat(e2, rbind(c(-0.73575875814475, 0.55181909965810),
14 :     c(-1.47151759908826, 1.10363824071557)),
15 :     tol = 1e-14)
16 : maechler 520 ## The ``surprising identity'' det(exp(A)) == exp( tr(A) )
17 :     ## or log det(exp(A)) == tr(A) :
18 :     stopifnot(all.equal(determinant(e2)$modulus, sum(diag(m2))))
19 : maechler 519
20 :     m3 <- Matrix(cbind(0,rbind(6*diag(3),0)), nc = 4)
21 :     e3 <- expm(m3)
22 :     assert.EQ.mat(e3,
23 :     rbind(c(1,6,18,36),
24 :     c(0,1, 6,18),
25 :     c(0,0, 1, 6),
26 :     c(0,0, 0, 1)))
27 :    

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge