SCM

SCM Repository

[matrix] Annotation of /pkg/tests/poMatrix.Rout.save
ViewVC logotype

Annotation of /pkg/tests/poMatrix.Rout.save

Parent Directory Parent Directory | Revision Log Revision Log


Revision 473 - (view) (download)

1 : maechler 470
2 :     R : Copyright 2005, The R Foundation for Statistical Computing
3 : maechler 473 Version 2.1.0 Under development (unstable) (2005-02-01), ISBN 3-900051-07-0
4 : maechler 470
5 :     R is free software and comes with ABSOLUTELY NO WARRANTY.
6 :     You are welcome to redistribute it under certain conditions.
7 :     Type 'license()' or 'licence()' for distribution details.
8 :    
9 :     R is a collaborative project with many contributors.
10 :     Type 'contributors()' for more information and
11 :     'citation()' on how to cite R or R packages in publications.
12 :    
13 :     Type 'demo()' for some demos, 'help()' for on-line help, or
14 :     'help.start()' for a HTML browser interface to help.
15 :     Type 'q()' to quit R.
16 :    
17 : maechler 473 > ### Testing positive definite matrices
18 :     >
19 : maechler 470 > library(Matrix)
20 : maechler 473 >
21 :     > stopifnot(c(0,0) == dim(Hilbert(0)))
22 :     >
23 : maechler 470 > h9 <- Hilbert(9)
24 :     > str(h9)
25 :     Formal class 'poMatrix' [package "Matrix"] with 5 slots
26 :     ..@ uplo : chr "U"
27 :     ..@ x : num [1:81] 1.000 0.500 0.333 0.250 0.200 ...
28 :     ..@ Dim : int [1:2] 9 9
29 :     ..@ rcond : num(0)
30 :     ..@ factorization: list()
31 : maechler 473 > all.equal(determinant(h9)$modulus, -96.7369450737858, tol= 1e-15)
32 :     [1] TRUE
33 :     > stopifnot(0 == length(h9@factorization))# nothing yet
34 :     > str(f9 <- as(chol(h9), "trMatrix"))
35 :     Formal class 'trMatrix' [package "Matrix"] with 6 slots
36 :     ..@ uplo : chr "U"
37 :     ..@ diag : chr "N"
38 :     ..@ x : num [1:81] 1.000 0.500 0.333 0.250 0.200 ...
39 :     ..@ Dim : int [1:2] 9 9
40 :     ..@ rcond : num(0)
41 :     ..@ factorization: list()
42 :     > ## h9 now has factorization
43 :     > stopifnot(names(h9@factorization) == "Cholesky")
44 :     > rcond(h9)
45 :     [1] 9.093796e-13
46 :     > rcond(f9)
47 :     [1] 9.127195e-07
48 :     > str(h9)# has 'rcond' and 'factorization'
49 : maechler 470 Formal class 'poMatrix' [package "Matrix"] with 5 slots
50 :     ..@ uplo : chr "U"
51 :     ..@ x : num [1:81] 1.000 0.500 0.333 0.250 0.200 ...
52 :     ..@ Dim : int [1:2] 9 9
53 : maechler 473 ..@ rcond : Named num 9.1e-13
54 :     .. ..- attr(*, "names")= chr "O"
55 : maechler 470 ..@ factorization:List of 1
56 :     .. ..$ Cholesky:Formal class 'Cholesky' [package "Matrix"] with 6 slots
57 :     .. .. .. ..@ uplo : chr "U"
58 :     .. .. .. ..@ diag : chr "N"
59 :     .. .. .. ..@ x : num [1:81] 1.000 0.500 0.333 0.250 0.200 ...
60 :     .. .. .. ..@ Dim : int [1:2] 9 9
61 :     .. .. .. ..@ rcond : num(0)
62 :     .. .. .. ..@ factorization: list()
63 :     > options(digits=4)
64 :     > crossprod(f9)# looks the same as
65 :     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
66 :     [1,] 1.0000 0.5000 0.33333 0.25000 0.20000 0.16667 0.14286 0.12500 0.11111
67 :     [2,] 0.5000 0.3333 0.25000 0.20000 0.16667 0.14286 0.12500 0.11111 0.10000
68 :     [3,] 0.3333 0.2500 0.20000 0.16667 0.14286 0.12500 0.11111 0.10000 0.09091
69 :     [4,] 0.2500 0.2000 0.16667 0.14286 0.12500 0.11111 0.10000 0.09091 0.08333
70 :     [5,] 0.2000 0.1667 0.14286 0.12500 0.11111 0.10000 0.09091 0.08333 0.07692
71 :     [6,] 0.1667 0.1429 0.12500 0.11111 0.10000 0.09091 0.08333 0.07692 0.07143
72 :     [7,] 0.1429 0.1250 0.11111 0.10000 0.09091 0.08333 0.07692 0.07143 0.06667
73 :     [8,] 0.1250 0.1111 0.10000 0.09091 0.08333 0.07692 0.07143 0.06667 0.06250
74 :     [9,] 0.1111 0.1000 0.09091 0.08333 0.07692 0.07143 0.06667 0.06250 0.05882
75 :     > h9 # but not internally!
76 :     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
77 :     [1,] 1.0000 0.5000 0.33333 0.25000 0.20000 0.16667 0.14286 0.12500 0.11111
78 :     [2,] 0.5000 0.3333 0.25000 0.20000 0.16667 0.14286 0.12500 0.11111 0.10000
79 :     [3,] 0.3333 0.2500 0.20000 0.16667 0.14286 0.12500 0.11111 0.10000 0.09091
80 :     [4,] 0.2500 0.2000 0.16667 0.14286 0.12500 0.11111 0.10000 0.09091 0.08333
81 :     [5,] 0.2000 0.1667 0.14286 0.12500 0.11111 0.10000 0.09091 0.08333 0.07692
82 :     [6,] 0.1667 0.1429 0.12500 0.11111 0.10000 0.09091 0.08333 0.07692 0.07143
83 :     [7,] 0.1429 0.1250 0.11111 0.10000 0.09091 0.08333 0.07692 0.07143 0.06667
84 :     [8,] 0.1250 0.1111 0.10000 0.09091 0.08333 0.07692 0.07143 0.06667 0.06250
85 :     [9,] 0.1111 0.1000 0.09091 0.08333 0.07692 0.07143 0.06667 0.06250 0.05882
86 :     > ## i.e. this is all wrong : all.equal(h9, crossprod(f9))
87 :     >

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