The R Project SVN R

Rev

Rev 42034 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42034 Rev 49068
Line 1... Line 1...
1
 
1
 
2
R version 2.6.0 Under development (unstable) (2007-06-23 r42031)
2
R version 2.10.0 Under development (unstable) (2009-08-04 r49064)
3
Copyright (C) 2007 The R Foundation for Statistical Computing
3
Copyright (C) 2009 The R Foundation for Statistical Computing
4
ISBN 3-900051-07-0
4
ISBN 3-900051-07-0
5
 
5
 
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
7
You are welcome to redistribute it under certain conditions.
7
You are welcome to redistribute it under certain conditions.
8
Type 'license()' or 'licence()' for distribution details.
8
Type 'license()' or 'licence()' for distribution details.
Line 15... Line 15...
15
'help.start()' for an HTML browser interface to help.
15
'help.start()' for an HTML browser interface to help.
16
Type 'q()' to quit R.
16
Type 'q()' to quit R.
17
 
17
 
18
> ### Tests of complex arithemetic.
18
> ### Tests of complex arithemetic.
19
> 
19
> 
-
 
20
> Meps <- .Machine$double.eps
20
> ## complex
21
> ## complex
21
> z <- 0i ^ (-3:3)
22
> z <- 0i ^ (-3:3)
22
> stopifnot(Re(z) == 0 ^ (-3:3))
23
> stopifnot(Re(z) == 0 ^ (-3:3))
23
> set.seed(123)
24
> set.seed(123)
24
> z <- complex(real = rnorm(100), imag = rnorm(100))
25
> z <- complex(real = rnorm(100), imag = rnorm(100))
25
> stopifnot(Mod ( 1 -  sin(z) / ( (exp(1i*z)-exp(-1i*z))/(2*1i) ))
26
> stopifnot(Mod ( 1 -  sin(z) / ( (exp(1i*z)-exp(-1i*z))/(2*1i) )) < 20 * Meps)
26
+ 	  < 20 * .Machine$double.eps)
-
 
27
> ## end of moved from complex.Rd
27
> ## end of moved from complex.Rd
28
> 
28
> 
29
> 
29
> 
30
> ## powers, including complex ones
30
> ## powers, including complex ones
31
> a <- -4:12
31
> a <- -4:12
Line 49... Line 49...
49
  8  0.354+0.000i 1+0i 2.828+0.000i  8+0i 22.627+0.000i  64+0i
49
  8  0.354+0.000i 1+0i 2.828+0.000i  8+0i 22.627+0.000i  64+0i
50
  9  0.333+0.000i 1+0i 3.000+0.000i  9+0i 27.000+0.000i  81+0i
50
  9  0.333+0.000i 1+0i 3.000+0.000i  9+0i 27.000+0.000i  81+0i
51
  10 0.316+0.000i 1+0i 3.162+0.000i 10+0i 31.623+0.000i 100+0i
51
  10 0.316+0.000i 1+0i 3.162+0.000i 10+0i 31.623+0.000i 100+0i
52
  11 0.302+0.000i 1+0i 3.317+0.000i 11+0i 36.483+0.000i 121+0i
52
  11 0.302+0.000i 1+0i 3.317+0.000i 11+0i 36.483+0.000i 121+0i
53
  12 0.289+0.000i 1+0i 3.464+0.000i 12+0i 41.569+0.000i 144+0i
53
  12 0.289+0.000i 1+0i 3.464+0.000i 12+0i 41.569+0.000i 144+0i
54
> 
-
 
-
 
54
> stopifnot(m[,as.character(0:2)] == cbind(1,a,a*a),
-
 
55
+                                         # latter were only approximate
-
 
56
+           all.equal(unname(m[,"0.5"]),
-
 
57
+                     sqrt(abs(a))*ifelse(a < 0, 1i, 1),
-
 
58
+                     tol= 20*Meps))
55
> ## fft():
59
> ## fft():
56
> for(n in 1:30) cat("\nn=",n,":", round(fft(1:n), 8),"\n")
60
> for(n in 1:30) cat("\nn=",n,":", round(fft(1:n), 8),"\n")
57
 
61
 
58
n= 1 : 1+0i 
62
n= 1 : 1+0i 
59
 
63
 
Line 115... Line 119...
115
 
119
 
116
n= 30 : 465+0i -15+142.7155i -15+70.56945i -15+46.16525i -15+33.69055i -15+25.98076i -15+20.64573i -15+16.65919i -15+13.50606i -15+10.89814i -15+8.66025i -15+6.67843i -15+4.8738i -15+3.18835i -15+1.57656i -15+0i -15-1.57656i -15-3.18835i -15-4.8738i -15-6.67843i -15-8.66025i -15-10.89814i -15-13.50606i -15-16.65919i -15-20.64573i -15-25.98076i -15-33.69055i -15-46.16525i -15-70.56945i -15-142.7155i 
120
n= 30 : 465+0i -15+142.7155i -15+70.56945i -15+46.16525i -15+33.69055i -15+25.98076i -15+20.64573i -15+16.65919i -15+13.50606i -15+10.89814i -15+8.66025i -15+6.67843i -15+4.8738i -15+3.18835i -15+1.57656i -15+0i -15-1.57656i -15-3.18835i -15-4.8738i -15-6.67843i -15-8.66025i -15-10.89814i -15-13.50606i -15-16.65919i -15-20.64573i -15-25.98076i -15-33.69055i -15-46.16525i -15-70.56945i -15-142.7155i 
117
> 
121
> 
118
> 
122
> 
119
> ## Complex Trig.:
123
> ## Complex Trig.:
120
> Meps <- .Machine$double.eps
-
 
121
> abs(Im(cos(acos(1i))) -	 1) < 2*Meps
124
> abs(Im(cos(acos(1i))) -	 1) < 2*Meps
122
[1] TRUE
125
[1] TRUE
123
> abs(Im(sin(asin(1i))) -	 1) < 2*Meps
126
> abs(Im(sin(asin(1i))) -	 1) < 2*Meps
124
[1] TRUE
127
[1] TRUE
125
> ##P (1 - Im(sin(asin(Ii))))/Meps
128
> ##P (1 - Im(sin(asin(Ii))))/Meps
Line 146... Line 149...
146
[1] TRUE
149
[1] TRUE
147
> ##P table(2*abs(Isi-1)	/ Meps)
150
> ##P table(2*abs(Isi-1)	/ Meps)
148
> 
151
> 
149
> 
152
> 
150
> ## polyroot():
153
> ## polyroot():
151
> all(abs(1 + polyroot(choose(8, 0:8))) < 1e-10)# maybe smaller..
154
> stopifnot(abs(1 + polyroot(choose(8, 0:8))) < 1e-10)# maybe smaller..
152
[1] TRUE
-
 
153
> 
155
> 
154
> 
156
> 
155
> ## PR#7781
157
> ## PR#7781
156
> ## This is not as given by e.g. glibc on AMD64
158
> ## This is not as given by e.g. glibc on AMD64
157
> (z <- tan(1+1000i)) # 0+1i from R's own code.
159
> (z <- tan(1+1000i)) # 0+1i from R's own code.