rb-gsl 1.15.3.1 → 1.15.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +2 -2
  3. data/ChangeLog +8 -0
  4. data/Rakefile +39 -96
  5. data/VERSION +1 -1
  6. data/ext/array.c +2 -2
  7. data/ext/block_source.c +1 -1
  8. data/ext/dirac.c +1 -1
  9. data/ext/eigen.c +13 -13
  10. data/ext/extconf.rb +17 -11
  11. data/ext/function.c +5 -5
  12. data/ext/gsl_narray.c +6 -6
  13. data/ext/histogram.c +7 -6
  14. data/ext/histogram2d.c +4 -4
  15. data/ext/interp.c +1 -1
  16. data/ext/linalg.c +13 -11
  17. data/ext/linalg_complex.c +8 -6
  18. data/ext/math.c +1 -1
  19. data/ext/matrix_complex.c +6 -6
  20. data/ext/matrix_source.c +10 -10
  21. data/ext/monte.c +2 -2
  22. data/ext/multimin.c +4 -4
  23. data/ext/multiroots.c +8 -8
  24. data/ext/nmf.c +6 -6
  25. data/ext/ntuple.c +4 -4
  26. data/ext/odeiv.c +2 -2
  27. data/ext/permutation.c +1 -1
  28. data/ext/poly2.c +6 -6
  29. data/ext/poly_source.c +9 -6
  30. data/ext/sf.c +31 -45
  31. data/ext/signal.c +2 -2
  32. data/ext/vector_complex.c +11 -10
  33. data/ext/vector_double.c +7 -4
  34. data/ext/vector_source.c +29 -26
  35. data/ext/wavelet.c +1 -1
  36. data/include/rb_gsl_common.h +12 -0
  37. data/include/rb_gsl_config.h +10 -1
  38. data/rdoc/blas.rdoc +4 -4
  39. data/rdoc/bspline.rdoc +8 -8
  40. data/rdoc/cheb.rdoc +9 -9
  41. data/rdoc/cholesky_complex.rdoc +1 -1
  42. data/rdoc/combi.rdoc +10 -10
  43. data/rdoc/complex.rdoc +12 -12
  44. data/rdoc/const.rdoc +21 -21
  45. data/rdoc/dht.rdoc +7 -7
  46. data/rdoc/diff.rdoc +7 -7
  47. data/rdoc/ehandling.rdoc +4 -4
  48. data/rdoc/eigen.rdoc +12 -12
  49. data/rdoc/fft.rdoc +27 -27
  50. data/rdoc/fit.rdoc +19 -19
  51. data/rdoc/function.rdoc +1 -1
  52. data/rdoc/graph.rdoc +3 -3
  53. data/rdoc/hist.rdoc +17 -17
  54. data/rdoc/hist2d.rdoc +5 -5
  55. data/rdoc/hist3d.rdoc +4 -4
  56. data/rdoc/index.rdoc +4 -4
  57. data/rdoc/integration.rdoc +17 -17
  58. data/rdoc/interp.rdoc +12 -12
  59. data/rdoc/intro.rdoc +4 -4
  60. data/rdoc/linalg.rdoc +21 -21
  61. data/rdoc/linalg_complex.rdoc +1 -1
  62. data/rdoc/math.rdoc +14 -14
  63. data/rdoc/matrix.rdoc +21 -21
  64. data/rdoc/min.rdoc +10 -10
  65. data/rdoc/monte.rdoc +4 -4
  66. data/rdoc/multimin.rdoc +13 -13
  67. data/rdoc/multiroot.rdoc +13 -13
  68. data/rdoc/narray.rdoc +10 -10
  69. data/rdoc/ndlinear.rdoc +5 -5
  70. data/rdoc/nonlinearfit.rdoc +18 -18
  71. data/rdoc/ntuple.rdoc +6 -6
  72. data/rdoc/odeiv.rdoc +13 -13
  73. data/rdoc/perm.rdoc +12 -12
  74. data/rdoc/poly.rdoc +18 -18
  75. data/rdoc/qrng.rdoc +10 -10
  76. data/rdoc/randist.rdoc +11 -11
  77. data/rdoc/ref.rdoc +50 -50
  78. data/rdoc/rng.rdoc +10 -10
  79. data/rdoc/rngextra.rdoc +5 -5
  80. data/rdoc/roots.rdoc +13 -13
  81. data/rdoc/sf.rdoc +36 -36
  82. data/rdoc/siman.rdoc +4 -4
  83. data/rdoc/sort.rdoc +7 -7
  84. data/rdoc/start.rdoc +1 -1
  85. data/rdoc/stats.rdoc +14 -14
  86. data/rdoc/sum.rdoc +5 -5
  87. data/rdoc/tensor.rdoc +4 -4
  88. data/rdoc/tut.rdoc +1 -1
  89. data/rdoc/use.rdoc +5 -5
  90. data/rdoc/vector.rdoc +29 -29
  91. data/rdoc/vector_complex.rdoc +6 -6
  92. data/rdoc/wavelet.rdoc +9 -9
  93. data/test/gsl/blas_test.rb +79 -0
  94. data/test/gsl/bspline_test.rb +63 -0
  95. data/test/gsl/cdf_test.rb +1512 -0
  96. data/test/gsl/cheb_test.rb +80 -0
  97. data/test/gsl/combination_test.rb +100 -0
  98. data/test/gsl/complex_test.rb +20 -0
  99. data/test/gsl/const_test.rb +29 -0
  100. data/test/gsl/deriv_test.rb +62 -0
  101. data/test/gsl/dht_test.rb +79 -0
  102. data/test/gsl/diff_test.rb +53 -0
  103. data/test/gsl/eigen_test.rb +563 -0
  104. data/test/gsl/err_test.rb +23 -0
  105. data/test/gsl/fit_test.rb +101 -0
  106. data/test/gsl/histo_test.rb +14 -0
  107. data/test/gsl/integration_test.rb +274 -0
  108. data/test/gsl/interp_test.rb +27 -0
  109. data/test/gsl/linalg_test.rb +463 -0
  110. data/test/gsl/matrix_nmf_test.rb +37 -0
  111. data/test/gsl/matrix_test.rb +77 -0
  112. data/test/gsl/min_test.rb +89 -0
  113. data/test/gsl/monte_test.rb +77 -0
  114. data/test/gsl/multifit_test.rb +753 -0
  115. data/test/gsl/multimin_test.rb +157 -0
  116. data/test/gsl/multiroot_test.rb +135 -0
  117. data/test/gsl/multiset_test.rb +52 -0
  118. data/test/gsl/odeiv_test.rb +275 -0
  119. data/test/gsl/poly_test.rb +338 -0
  120. data/test/gsl/qrng_test.rb +94 -0
  121. data/test/gsl/quartic_test.rb +28 -0
  122. data/test/gsl/randist_test.rb +122 -0
  123. data/test/gsl/rng_test.rb +303 -0
  124. data/test/gsl/roots_test.rb +78 -0
  125. data/test/gsl/sf_test.rb +2079 -0
  126. data/test/gsl/stats_test.rb +122 -0
  127. data/test/gsl/sum_test.rb +69 -0
  128. data/test/gsl/tensor_test.rb +396 -0
  129. data/test/gsl/vector_test.rb +223 -0
  130. data/test/gsl/wavelet_test.rb +130 -0
  131. data/test/gsl_test.rb +321 -0
  132. data/test/test_helper.rb +42 -0
  133. metadata +107 -150
  134. data/setup.rb +0 -1585
  135. data/tests/blas/amax.rb +0 -14
  136. data/tests/blas/asum.rb +0 -16
  137. data/tests/blas/axpy.rb +0 -25
  138. data/tests/blas/copy.rb +0 -23
  139. data/tests/blas/dot.rb +0 -23
  140. data/tests/bspline.rb +0 -53
  141. data/tests/cdf.rb +0 -1388
  142. data/tests/cheb.rb +0 -112
  143. data/tests/combination.rb +0 -123
  144. data/tests/complex.rb +0 -17
  145. data/tests/const.rb +0 -24
  146. data/tests/deriv.rb +0 -85
  147. data/tests/dht/dht1.rb +0 -17
  148. data/tests/dht/dht2.rb +0 -23
  149. data/tests/dht/dht3.rb +0 -23
  150. data/tests/dht/dht4.rb +0 -23
  151. data/tests/diff.rb +0 -78
  152. data/tests/eigen/eigen.rb +0 -220
  153. data/tests/eigen/gen.rb +0 -105
  154. data/tests/eigen/genherm.rb +0 -66
  155. data/tests/eigen/gensymm.rb +0 -68
  156. data/tests/eigen/nonsymm.rb +0 -53
  157. data/tests/eigen/nonsymmv.rb +0 -53
  158. data/tests/eigen/symm-herm.rb +0 -74
  159. data/tests/err.rb +0 -58
  160. data/tests/fit.rb +0 -124
  161. data/tests/gsl_test.rb +0 -118
  162. data/tests/gsl_test2.rb +0 -110
  163. data/tests/histo.rb +0 -12
  164. data/tests/integration/integration1.rb +0 -72
  165. data/tests/integration/integration2.rb +0 -71
  166. data/tests/integration/integration3.rb +0 -71
  167. data/tests/integration/integration4.rb +0 -71
  168. data/tests/interp.rb +0 -45
  169. data/tests/linalg/HH.rb +0 -64
  170. data/tests/linalg/LU.rb +0 -47
  171. data/tests/linalg/QR.rb +0 -77
  172. data/tests/linalg/SV.rb +0 -24
  173. data/tests/linalg/TDN.rb +0 -116
  174. data/tests/linalg/TDS.rb +0 -122
  175. data/tests/linalg/bidiag.rb +0 -73
  176. data/tests/linalg/cholesky.rb +0 -20
  177. data/tests/linalg/linalg.rb +0 -158
  178. data/tests/matrix/matrix_complex_test.rb +0 -36
  179. data/tests/matrix/matrix_nmf_test.rb +0 -39
  180. data/tests/matrix/matrix_test.rb +0 -48
  181. data/tests/min.rb +0 -99
  182. data/tests/monte/miser.rb +0 -31
  183. data/tests/monte/vegas.rb +0 -45
  184. data/tests/multifit/test_2dgauss.rb +0 -112
  185. data/tests/multifit/test_brown.rb +0 -90
  186. data/tests/multifit/test_enso.rb +0 -246
  187. data/tests/multifit/test_filip.rb +0 -155
  188. data/tests/multifit/test_gauss.rb +0 -97
  189. data/tests/multifit/test_longley.rb +0 -110
  190. data/tests/multifit/test_multifit.rb +0 -52
  191. data/tests/multimin.rb +0 -139
  192. data/tests/multiroot.rb +0 -131
  193. data/tests/multiset.rb +0 -52
  194. data/tests/narray/blas_dnrm2.rb +0 -20
  195. data/tests/odeiv.rb +0 -353
  196. data/tests/poly/poly.rb +0 -290
  197. data/tests/poly/special.rb +0 -65
  198. data/tests/qrng.rb +0 -131
  199. data/tests/quartic.rb +0 -29
  200. data/tests/randist.rb +0 -134
  201. data/tests/rng.rb +0 -305
  202. data/tests/roots.rb +0 -76
  203. data/tests/run-test.sh +0 -17
  204. data/tests/sf/gsl_test_sf.rb +0 -249
  205. data/tests/sf/test_airy.rb +0 -83
  206. data/tests/sf/test_bessel.rb +0 -306
  207. data/tests/sf/test_coulomb.rb +0 -17
  208. data/tests/sf/test_dilog.rb +0 -25
  209. data/tests/sf/test_gamma.rb +0 -209
  210. data/tests/sf/test_hyperg.rb +0 -356
  211. data/tests/sf/test_legendre.rb +0 -227
  212. data/tests/sf/test_mathieu.rb +0 -59
  213. data/tests/sf/test_mode.rb +0 -19
  214. data/tests/sf/test_sf.rb +0 -839
  215. data/tests/stats.rb +0 -174
  216. data/tests/stats_mt.rb +0 -16
  217. data/tests/sum.rb +0 -98
  218. data/tests/sys.rb +0 -323
  219. data/tests/tensor.rb +0 -419
  220. data/tests/vector/vector_complex_test.rb +0 -101
  221. data/tests/vector/vector_test.rb +0 -141
  222. data/tests/wavelet.rb +0 -142
@@ -0,0 +1,338 @@
1
+ require 'test_helper'
2
+
3
+ class PolyTest < GSL::TestCase
4
+
5
+ EPS = 100.0 * GSL::DBL_EPSILON
6
+
7
+ def test_poly
8
+ c = GSL::Poly.alloc(1.0, 0.5, 0.3)
9
+ x = 0.5
10
+ y = c.eval(x)
11
+ assert_rel y, 1 + 0.5 * x + 0.3 * x * x, EPS, 'gsl_poly_eval({1, 0.5, 0.3}, 0.5)'
12
+
13
+ d = GSL::Poly.alloc( 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1)
14
+ x = 1.0
15
+ y = GSL::Poly.eval(d, x)
16
+ assert_rel y, 1.0, EPS, 'gsl_poly_eval({1,-1, 1, -1, 1, -1, 1, -1, 1, -1, 1}, 1.0)'
17
+
18
+ x0, x1 = GSL::Poly.solve_quadratic(4.0, -20.0, 25.0).to_a
19
+ assert_rel x0, 2.5, 1e-9, 'x0, (2x - 5)^2 = 0'
20
+ assert_rel x1, 2.5, 1e-9, 'x1, (2x - 5)^2 = 0'
21
+
22
+ x0, x1 = GSL::Poly.solve_quadratic(4.0, 7.0, 0.0).to_a
23
+ assert_rel x0, -1.75, 1e-9, 'x0, x(4x + 7) = 0'
24
+ assert_rel x1, 0.0, 1e-9, 'x1, x(4x + 7) = 0'
25
+
26
+ x0, x1 = GSL::Poly.solve_quadratic(5.0, 0.0, -20.0).to_a
27
+ assert_rel x0, -2.0, 1e-9, 'x0, 5 x^2 = 20'
28
+ assert_rel x1, 2.0, 1e-9, 'x1, 5 x^2 = 20'
29
+
30
+ # Quadratic single real root (technically not a quadratic)
31
+ x0, x1 = GSL::Poly.solve_quadratic(0.0, 1.0, 0.0).to_a
32
+ assert_rel x0, 0.0, 0, 'x0, x = 0'
33
+ assert x1.nil?, 'x1, x = 0 is nil'
34
+
35
+ # Quadratic no real root
36
+ x0, x1 = GSL::Poly.solve_quadratic(1.0, 0.0, 1.0).to_a
37
+ assert x0.nil?, 'x0, x^2 = -1 is nil'
38
+ assert x1.nil?, 'x1, x^2 = -1 is nil'
39
+
40
+ x0, x1, x2 = GSL::Poly.solve_cubic(0.0, 0.0, -27.0).to_a
41
+ assert_rel x0, 3.0, 1e-9, 'x0, x^3 = 27'
42
+
43
+ # Cubic triple real root
44
+ x0, x1, x2 = GSL::Poly.solve_cubic(-51.0, 867.0, -4913.0).to_a
45
+ assert_rel x0, 17.0, 1e-9, 'x0, (x-17)^3=0'
46
+ assert_rel x1, 17.0, 1e-9, 'x1, (x-17)^3=0'
47
+ assert_rel x2, 17.0, 1e-9, 'x2, (x-17)^3=0'
48
+
49
+ # Cubic double real root plus single real root
50
+ x0, x1, x2 = GSL::Poly.solve_cubic(-57.0, 1071.0, -6647.0).to_a
51
+ assert_rel x0, 17.0, 1e-9, 'x0, (x-17)(x-17)(x-23)=0'
52
+ assert_rel x1, 17.0, 1e-9, 'x1, (x-17)(x-17)(x-23)=0'
53
+ assert_rel x2, 23.0, 1e-9, 'x2, (x-17)(x-17)(x-23)=0'
54
+
55
+ x0, x1, x2 = GSL::Poly.solve_cubic(-11.0, -493.0, +6647.0).to_a
56
+ assert_rel x0, -23.0, 1e-9, 'x0, (x+23)(x-17)(x-17)=0'
57
+ assert_rel x1, 17.0, 1e-9, 'x1, (x+23)(x-17)(x-17)=0'
58
+ assert_rel x2, 17.0, 1e-9, 'x2, (x+23)(x-17)(x-17)=0'
59
+
60
+ x0, x1, x2 = GSL::Poly.solve_cubic(-143.0, 5087.0, -50065.0).to_a
61
+ assert_rel x0, 17.0, 1e-9, 'x0, (x-17)(x-31)(x-95)=0'
62
+ assert_rel x1, 31.0, 1e-9, 'x1, (x-17)(x-31)(x-95)=0'
63
+ assert_rel x2, 95.0, 1e-9, 'x2, (x-17)(x-31)(x-95)=0'
64
+
65
+ x0, x1, x2 = GSL::Poly.solve_cubic(-109.0, 803.0, 50065.0).to_a
66
+ assert_rel x0, -17.0, 1e-9, 'x0, (x+17)(x-31)(x-95)=0'
67
+ assert_rel x1, 31.0, 1e-9, 'x1, (x+17)(x-31)(x-95)=0'
68
+ assert_rel x2, 95.0, 1e-9, 'x2, (x+17)(x-31)(x-95)=0'
69
+
70
+ # Cubic double real root only is impossible
71
+
72
+ # Cubic single real root (and two complex roots, not returned)
73
+ x0, x1, x2 = GSL::Poly.solve_cubic(0.0, 0.0, -1.0).to_a
74
+ assert_rel x0, 1.0, 1e-9, 'x0, x^3 = 1'
75
+ assert x1.nil?, 'x1, x^3 = 1 is nil'
76
+ assert x2.nil?, 'x2, x^3 = 1 is nil'
77
+
78
+ # Cubic no real root is impossible
79
+
80
+ z = GSL::Poly::Complex.solve_quadratic(4.0, -20.0, 26.0)
81
+ assert_rel z[0].re, 2.5, 1e-9, 'z0.real, (2x - 5)^2 = -1'
82
+ assert_rel z[0].im, -0.5, 1e-9, 'z0.imag, (2x - 5)^2 = -1'
83
+ assert_rel z[1].re, 2.5, 1e-9, 'z1.real, (2x - 5)^2 = -1'
84
+ assert_rel z[1].im, 0.5, 1e-9, 'z1.imag, (2x - 5)^2 = -1'
85
+
86
+ z = GSL::Poly.complex_solve_quadratic(4.0, -20.0, 25.0)
87
+ assert_rel z[0].re, 2.5, 1e-9, 'z0.real, (2x - 5)^2 = 0'
88
+ assert_rel z[0].im, 0.0, 1e-9, 'z0.imag (2x - 5)^2 = 0'
89
+ assert_rel z[1].re, 2.5, 1e-9, 'z1.real, (2x - 5)^2 = 0'
90
+ assert_rel z[1].im, 0.0, 1e-9, 'z1.imag (2x - 5)^2 = 0'
91
+ assert_equal z[0].re, z[1].re, 'z0.real == z1.real, (2x - 5)^2 = 0'
92
+ assert_equal z[1].im, z[1].im, 'z0.imag == z1.imag, (2x - 5)^2 = 0'
93
+
94
+ z = GSL::Poly.complex_solve_quadratic(4.0, -20.0, 21.0)
95
+ assert_rel z[0].re, 1.5, 1e-9, 'z0.real, (2x - 5)^2 = 4'
96
+ assert_rel z[0].im, 0.0, 1e-9, 'z0.imag, (2x - 5)^2 = 4'
97
+ assert_rel z[1].re, 3.5, 1e-9, 'z1.real, (2x - 5)^2 = 4'
98
+ assert_rel z[1].im, 0.0, 1e-9, 'z1.imag, (2x - 5)^2 = 4'
99
+
100
+ z = GSL::Poly.complex_solve_quadratic(4.0, 7.0, 0.0)
101
+ assert_rel z[0].re, -1.75, 1e-9, 'z[0].real, x(4x + 7) = 0'
102
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, x(4x + 7) = 0'
103
+ assert_rel z[1].re, 0.0, 1e-9, 'z[1].real, x(4x + 7) = 0'
104
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, x(4x + 7) = 0'
105
+
106
+ z = GSL::Poly.complex_solve_quadratic(5.0, 0.0, -20.0)
107
+ assert_rel z[0].re, -2.0, 1e-9, 'z[0].real, 5 x^2 = 20'
108
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, 5 x^2 = 20'
109
+ assert_rel z[1].re, 2.0, 1e-9, 'z[1].real, 5 x^2 = 20'
110
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, 5 x^2 = 20'
111
+
112
+ z = GSL::Poly.complex_solve_quadratic(5.0, 0.0, 20.0)
113
+ assert_rel z[0].re, 0.0, 1e-9, 'z[0].real, 5 x^2 = -20'
114
+ assert_rel z[0].im, -2.0, 1e-9, 'z[0].imag, 5 x^2 = -20'
115
+ assert_rel z[1].re, 0.0, 1e-9, 'z[1].real, 5 x^2 = -20'
116
+ assert_rel z[1].im, 2.0, 1e-9, 'z[1].imag, 5 x^2 = -20'
117
+
118
+ # Quadratic single complex root (technically not quadratic and root not
119
+ # complex since imaginary component is 0, but the data type is complex)
120
+ z = GSL::Poly.complex_solve_quadratic(0.0, 1.0, -1.0)
121
+ assert_rel z[0].re, 1.0, 1e-9, 'z[0].real, x = 1 (complex)'
122
+ assert_rel z[0].im, 0.0, 0.0, 'z[0].imag, x = 1 (complex)'
123
+ assert x1.nil?, 'z[1], x = 0 is nil'
124
+
125
+ # Quadratic no complex root (technically not quadratic)
126
+ z = GSL::Poly.complex_solve_quadratic(0.0, 0.0, 1.0)
127
+ assert z[0].nil?, 'z[0], 1 = 0 is nil'
128
+ assert z[1].nil?, 'z[1], 1 = 0 is nil'
129
+
130
+ z = GSL::Poly.complex_solve_cubic(0.0, 0.0, -27.0)
131
+ assert_rel z[0].re, -1.5, 1e-9, 'z[0].real, x^3 = 27'
132
+ assert_rel z[0].im, -1.5 * Math.sqrt(3.0), 1e-9, 'z[0].imag, x^3 = 27'
133
+ assert_rel z[1].re, -1.5, 1e-9, 'z[1].real, x^3 = 27'
134
+ assert_rel z[1].im, 1.5 * Math.sqrt(3.0), 1e-9, 'z[1].imag, x^3 = 27'
135
+ assert_rel z[2].re, 3.0, 1e-9, 'z[2].real, x^3 = 27'
136
+ assert_rel z[2].im, 0.0, 1e-9, 'z[2].imag, x^3 = 27'
137
+
138
+ z = GSL::Poly.complex_solve_cubic(-1.0, 1.0, 39.0)
139
+ assert_rel z[0].re, -3.0, 1e-9, 'z[0].real, (x+3)(x^2+1) = 0'
140
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, (x+3)(x^2+1) = 0'
141
+ assert_rel z[1].re, 2.0, 1e-9, 'z[1].real, (x+3)(x^2+1) = 0'
142
+ assert_rel z[1].im, -3.0, 1e-9, 'z[1].imag, (x+3)(x^2+1) = 0'
143
+ assert_rel z[2].re, 2.0, 1e-9, 'z[2].real, (x+3)(x^2+1) = 0'
144
+ assert_rel z[2].im, 3.0, 1e-9, 'z[2].imag, (x+3)(x^2+1) = 0'
145
+
146
+ z = GSL::Poly.complex_solve_cubic(-51.0, 867.0, -4913.0)
147
+ assert_rel z[0].re, 17.0, 1e-9, 'z[0].real, (x-17)^3=0'
148
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, (x-17)^3=0'
149
+ assert_rel z[1].re, 17.0, 1e-9, 'z[1].real, (x-17)^3=0'
150
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, (x-17)^3=0'
151
+ assert_rel z[2].re, 17.0, 1e-9, 'z[2].real, (x-17)^3=0'
152
+ assert_rel z[2].im, 0.0, 1e-9, 'z[2].imag, (x-17)^3=0'
153
+
154
+ z = GSL::Poly.complex_solve_cubic(-57.0, 1071.0, -6647.0)
155
+ assert_rel z[0].re, 17.0, 1e-9, 'z[0].real, (x-17)(x-17)(x-23)=0'
156
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, (x-17)(x-17)(x-23)=0'
157
+ assert_rel z[1].re, 17.0, 1e-9, 'z[1].real, (x-17)(x-17)(x-23)=0'
158
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, (x-17)(x-17)(x-23)=0'
159
+ assert_rel z[2].re, 23.0, 1e-9, 'z[2].real, (x-17)(x-17)(x-23)=0'
160
+ assert_rel z[2].im, 0.0, 1e-9, 'z[2].imag, (x-17)(x-17)(x-23)=0'
161
+
162
+ z = GSL::Poly.complex_solve_cubic(-11.0, -493.0, +6647.0)
163
+ assert_rel z[0].re, -23.0, 1e-9, 'z[0].real, (x+23)(x-17)(x-17)=0'
164
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, (x+23)(x-17)(x-17)=0'
165
+ assert_rel z[1].re, 17.0, 1e-9, 'z[1].real, (x+23)(x-17)(x-17)=0'
166
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, (x+23)(x-17)(x-17)=0'
167
+ assert_rel z[2].re, 17.0, 1e-9, 'z[2].real, (x+23)(x-17)(x-17)=0'
168
+ assert_rel z[2].im, 0.0, 1e-9, 'z[2].imag, (x+23)(x-17)(x-17)=0'
169
+
170
+ z = GSL::Poly.complex_solve_cubic(-143.0, 5087.0, -50065.0)
171
+ assert_rel z[0].re, 17.0, 1e-9, 'z[0].real, (x-17)(x-31)(x-95)=0'
172
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, (x-17)(x-31)(x-95)=0'
173
+ assert_rel z[1].re, 31.0, 1e-9, 'z[1].real, (x-17)(x-31)(x-95)=0'
174
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, (x-17)(x-31)(x-95)=0'
175
+ assert_rel z[2].re, 95.0, 1e-9, 'z[2].real, (x-17)(x-31)(x-95)=0'
176
+ assert_rel z[2].im, 0.0, 1e-9, 'z[2].imag, (x-17)(x-31)(x-95)=0'
177
+
178
+ a = GSL::Poly.alloc(-120, 274, -225, 85, -15, 1)
179
+ w = GSL::Poly::Complex::Workspace.alloc(a.size)
180
+ z = GSL::Poly.complex_solve(a, 6, w)
181
+ assert_rel z[0].re, 1.0, 1e-9, 'z[0].real, 5th-order polynomial'
182
+ assert_rel z[0].im, 0.0, 1e-9, 'z[0].imag, 5th-order polynomial'
183
+ assert_rel z[1].re, 2.0, 1e-9, 'z[1].real, 5th-order polynomial'
184
+ assert_rel z[1].im, 0.0, 1e-9, 'z[1].imag, 5th-order polynomial'
185
+ assert_rel z[2].re, 3.0, 1e-9, 'z[2].real, 5th-order polynomial'
186
+ assert_rel z[2].im, 0.0, 1e-9, 'z[2].imag, 5th-order polynomial'
187
+ assert_rel z[3].re, 4.0, 1e-9, 'z3.real, 5th-order polynomial'
188
+ assert_rel z[3].im, 0.0, 1e-9, 'z3.imag, 5th-order polynomial'
189
+ assert_rel z[4].re, 5.0, 1e-9, 'z4.real, 5th-order polynomial'
190
+ assert_rel z[4].im, 0.0, 1e-9, 'z4.imag, 5th-order polynomial'
191
+
192
+ a = GSL::Poly.alloc(1, 0, 0, 0, 1, 0, 0, 0, 1)
193
+ w = GSL::Poly::Complex::Workspace.alloc(a.size)
194
+ c = 0.5
195
+ s = Math.sqrt(3) / 2
196
+ z = GSL::Poly.complex_solve(a, w)
197
+ assert_rel z[0].re, -s, 1e-9, 'z[0].real, 8th-order polynomial'
198
+ assert_rel z[0].im, c, 1e-9, 'z[0].imag, 8th-order polynomial'
199
+ assert_rel z[1].re, -s, 1e-9, 'z[1].real, 8th-order polynomial'
200
+ assert_rel z[1].im, -c, 1e-9, 'z[1].imag, 8th-order polynomial'
201
+ assert_rel z[2].re, -c, 1e-9, 'z[2].real, 8th-order polynomial'
202
+ assert_rel z[2].im, s, 1e-9, 'z[2].imag, 8th-order polynomial'
203
+ assert_rel z[3].re, -c, 1e-9, 'z3.real, 8th-order polynomial'
204
+ assert_rel z[3].im, -s, 1e-9, 'z3.imag, 8th-order polynomial'
205
+ assert_rel z[4].re, c, 1e-9, 'z4.real, 8th-order polynomial'
206
+ assert_rel z[4].im, s, 1e-9, 'z4.imag, 8th-order polynomial'
207
+ assert_rel z[5].re, c, 1e-9, 'z5.real, 8th-order polynomial'
208
+ assert_rel z[5].im, -s, 1e-9, 'z5.imag, 8th-order polynomial'
209
+ assert_rel z[6].re, s, 1e-9, 'z6.real, 8th-order polynomial'
210
+ assert_rel z[6].im, c, 1e-9, 'z6.imag, 8th-order polynomial'
211
+ assert_rel z[7].re, s, 1e-9, 'z7.real, 8th-order polynomial'
212
+ assert_rel z[7].im, -c, 1e-9, 'z7.imag, 8th-order polynomial'
213
+
214
+ xa = GSL::Poly.alloc(0.16, 0.97, 1.94, 2.74, 3.58, 3.73, 4.70)
215
+ ya = GSL::Poly.alloc(0.73, 1.11, 1.49, 1.84, 2.30, 2.41, 3.07)
216
+ dd_expected = GSL::Vector.alloc(7.30000000000000e-01,
217
+ 4.69135802469136e-01,
218
+ -4.34737219941284e-02,
219
+ 2.68681098870099e-02,
220
+ -3.22937056934996e-03,
221
+ 6.12763259971375e-03,
222
+ -6.45402453527083e-03)
223
+ dd = GSL::Poly.dd_init(xa, ya)
224
+
225
+ 7.times { |i|
226
+ assert_rel dd[i], dd_expected[i], 1e-10, "divided difference dd[#{i}]"
227
+ }
228
+
229
+ 7.times { |i|
230
+ y = dd.eval(xa, xa[i])
231
+ assert_rel y, ya[i], 1e-10, "divided difference y[#{i}]"
232
+ }
233
+
234
+ coeff = dd.taylor(1.5, xa)
235
+
236
+ 7.times { |i|
237
+ y = coeff.eval(xa[i] - 1.5)
238
+ assert_rel y, ya[i], 1e-10, "taylor expansion about 1.5 y[#{i}]"
239
+ }
240
+
241
+ # Added GSL-1.12.90 (gsl-1.13)
242
+ # gsl_poly_eval_derivs()
243
+ return unless GSL::Poly.method_defined?(:eval_derivs)
244
+
245
+ c = GSL::Vector.alloc([1.0, -2.0, 3.0, -4.0, 5.0, -6.0])
246
+ x = -0.5
247
+
248
+ dc = GSL::Poly.eval_derivs(c, x)
249
+
250
+ assert_rel dc[0], c[0] + c[1] * x + c[2] * x * x + c[3] * x * x * x + c[4] * x * x * x * x + c[5] * x * x * x * x * x , EPS, 'eval_derivs({+1, -2, +3, -4, +5, -6}, 3.75)'
251
+ assert_rel dc[1], c[1] + 2.0 * c[2] * x + 3.0 * c[3] * x * x + 4.0 * c[4] * x * x * x + 5.0 * c[5] * x * x * x * x , EPS, 'eval_derivs({+1, -2, +3, -4, +5, -6} deriv 1, -12.375)'
252
+ assert_rel dc[2], 2.0 * c[2] + 3.0 * 2.0 * c[3] * x + 4.0 * 3.0 * c[4] * x * x + 5.0 * 4.0 * c[5] * x * x * x , EPS, 'eval_derivs({+1, -2, +3, -4, +5, -6} deriv 2, +48.0)'
253
+ assert_rel dc[3], 3.0 * 2.0 * c[3] + 4.0 * 3.0 * 2.0 * c[4] * x + 5.0 * 4.0 * 3.0 * c[5] * x * x , EPS, 'eval_derivs({+1, -2, +3, -4, +5, -6} deriv 3, -174.0)'
254
+ assert_rel dc[4], 4.0 * 3.0 * 2.0 * c[4] + 5.0 * 4.0 * 3.0 * 2.0 * c[5] * x, EPS, 'eval_derivs({+1, -2, +3, -4, +5, -6} deriv 4, +480.0)'
255
+ assert_rel dc[5], 5.0 * 4.0 * 3.0 * 2.0 * c[5] , EPS, 'eval_derivs({+1, -2, +3, -4, +5, -6} deriv 5, -720.0)'
256
+
257
+ # Test Poly::fit and Poly::wfit
258
+ x = GSL::Vector[0, 2, 2]
259
+ y = GSL::Vector[0, 1, -1]
260
+ coef, cov, chisq, status = GSL::Poly.fit(x, y, 1)
261
+ assert_rel coef[0], 0.0, 1e-9, 'y intercept == 0'
262
+ assert_rel coef[1], 0.0, 1e-9, 'slope == 0'
263
+ assert_rel chisq, 2.0, 1e-9, 'chisq == 2'
264
+
265
+ w = GSL::Vector[1, 1, 0]
266
+ coef, cov, chisq, status = GSL::Poly.wfit(x, w, y, 1)
267
+ assert_rel coef[0], 0.0, 1e-9, 'y intercept == 0'
268
+ assert_rel coef[1], 0.5, 1e-9, 'slope == 0.5'
269
+ assert_rel chisq, 0.0, 1e-9, 'chisq == 0'
270
+ end
271
+
272
+ def test_special
273
+ hermit = [
274
+ GSL::Poly::Int[1],
275
+ GSL::Poly::Int[0, 2],
276
+ GSL::Poly::Int[-2, 0, 4],
277
+ GSL::Poly::Int[0, -12, 0, 8],
278
+ GSL::Poly::Int[12, 0, -48, 0, 16],
279
+ GSL::Poly::Int[0, 120, 0, -160, 0, 32],
280
+ GSL::Poly::Int[-120, 0, 720, 0, -480, 0, 64]
281
+ ]
282
+ hermit[0][0] = 1
283
+
284
+ 6.times { |i|
285
+ hn = GSL::Poly.hermite(i)
286
+ assert_equal hermit[i], hn, "Hermite polynomial, n = #{i}"
287
+ }
288
+
289
+ laguerre = [
290
+ GSL::Poly::Int[1],
291
+ GSL::Poly::Int[1, -1],
292
+ GSL::Poly::Int[2, -4, 1],
293
+ GSL::Poly::Int[6, -18, 9, -1],
294
+ GSL::Poly::Int[24, -96, 72, -16, 1],
295
+ GSL::Poly::Int[120, -600, 600, -200, 25, -1],
296
+ GSL::Poly::Int[720, -4320, 5400, -2400, 450, -36, 1]
297
+ ]
298
+ laguerre[0][0] = 1
299
+
300
+ 7.times { |i|
301
+ hn = GSL::Poly.laguerre(i)
302
+ assert_equal laguerre[i], hn, "Laguerre polynomial, n = #{i}"
303
+ }
304
+
305
+ cheb = [
306
+ GSL::Poly::Int[1],
307
+ GSL::Poly::Int[0, 1],
308
+ GSL::Poly::Int[-1, 0, 2],
309
+ GSL::Poly::Int[0, -3, 0, 4],
310
+ GSL::Poly::Int[1, 0, -8, 0, 8],
311
+ GSL::Poly::Int[0, 5, 0, -20, 0, 16],
312
+ GSL::Poly::Int[-1, 0, 18, 0, -48, 0, 32]
313
+ ]
314
+ cheb[0][0] = 1
315
+
316
+ 7.times { |i|
317
+ hn = GSL::Poly.cheb(i)
318
+ assert_equal cheb[i], hn, "Chebyshev polynomial, n = #{i}"
319
+ }
320
+
321
+ cheb_ii = [
322
+ GSL::Poly::Int[1],
323
+ GSL::Poly::Int[0, 2],
324
+ GSL::Poly::Int[-1, 0, 4],
325
+ GSL::Poly::Int[0, -4, 0, 8],
326
+ GSL::Poly::Int[1, 0, -12, 0, 16],
327
+ GSL::Poly::Int[0, 6, 0, -32, 0, 32],
328
+ GSL::Poly::Int[-1, 0, 24, 0, -80, 0, 64]
329
+ ]
330
+ cheb_ii[0][0] = 1
331
+
332
+ 7.times { |i|
333
+ hn = GSL::Poly.cheb_II(i)
334
+ assert_equal cheb_ii[i], hn, "Chebyshev II polynomial, n = #{i}"
335
+ }
336
+ end
337
+
338
+ end
@@ -0,0 +1,94 @@
1
+ require 'test_helper'
2
+
3
+ class QRngTest < GSL::TestCase
4
+
5
+ def _test_sobol(v, d, g = nil)
6
+ status = 0
7
+
8
+ if g
9
+ g.init
10
+ reinitialized = true
11
+ else
12
+ g = GSL::QRng.alloc(GSL::QRng::SOBOL, d)
13
+ end
14
+
15
+ 3.times { g.get(v) }
16
+
17
+ status += (v[0] != 0.25 || v[1] != 0.75) ? 1 : 0
18
+ g.get(v)
19
+
20
+ status += (v[0] != 0.375 || v[1] != 0.375) ? 1 : 0
21
+ assert status.zero?, "Sobol d=#{d}#{' (reinitialized)' if reinitialized}"
22
+
23
+ g
24
+ end
25
+
26
+ def test_sobol
27
+ v = GSL::Vector.alloc(3)
28
+
29
+ _test_sobol(v, 2)
30
+ _test_sobol(v, 3, _test_sobol(v, 3))
31
+ end
32
+
33
+ def _test_nied2(v, d, g = nil)
34
+ status = 0
35
+
36
+ if g
37
+ g.init
38
+ reinitialized = true
39
+ else
40
+ g = GSL::QRng.alloc(GSL::QRng::NIEDERREITER_2, d)
41
+ end
42
+
43
+ 3.times { g.get(v) }
44
+
45
+ status += (v[0] != 0.75 || v[1] != 0.25) ? 1 : 0
46
+ g.get(v)
47
+
48
+ status += (v[0] != 0.25 || v[1] != 0.75) ? 1 : 0
49
+ 3.times { g.get(v) }
50
+
51
+ status += (v[0] != 0.625 || v[1] != 0.125) ? 1 : 0
52
+ assert status.zero?, "Niederreiter d=#{d}#{' (reinitialized)' if reinitialized}"
53
+
54
+ g
55
+ end
56
+
57
+ def test_nied2
58
+ v = GSL::Vector.alloc(3)
59
+
60
+ _test_nied2(v, 2)
61
+ _test_nied2(v, 3, _test_nied2(v, 3))
62
+ end
63
+
64
+ def _test_hdsobol(v, d, g = nil)
65
+ status = 0
66
+
67
+ if g
68
+ g.init
69
+ reinitialized = true
70
+ else
71
+ g = GSL::QRng.alloc(GSL::QRng::HDSOBOL, d)
72
+ end
73
+
74
+ 3.times { g.get(v) }
75
+
76
+ status += (v[0] != 0.25 || v[1] != 0.75) ? 1 : 0
77
+ g.get(v)
78
+
79
+ status += (v[0] != 0.375 || v[1] != 0.375) ? 1 : 0
80
+ assert status.zero?, "HDSobol d=#{d}#{' (reinitialized)' if reinitialized}"
81
+
82
+ g
83
+ end
84
+
85
+ def test_hdsobol
86
+ return unless GSL::QRng.const_defined?(:HDSOBOL)
87
+
88
+ v = GSL::Vector.alloc(3)
89
+
90
+ _test_hdsobol(v, 2)
91
+ _test_hdsobol(v, 3, _test_hdsobol(v, 3))
92
+ end
93
+
94
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class QuarticTest < GSL::TestCase
4
+
5
+ def _test_quartic(n, *sol)
6
+ z = GSL::Poly.complex_solve_quartic(0.0, 0.0, 0.0, n)
7
+ desc = "Four roots, x^4 #{n}"
8
+
9
+ assert_rel z[0].re, sol[0], 1e-9, "#{desc}: z0.real"
10
+ assert_rel z[0].im, sol[1], 1e-9, "#{desc}: z0.imag"
11
+ assert_rel z[1].re, sol[2], 1e-9, "#{desc}: z1.real"
12
+ assert_rel z[1].im, sol[3], 1e-9, "#{desc}: z1.imag"
13
+ assert_rel z[2].re, sol[4], 1e-9, "#{desc}: z2.real"
14
+ assert_rel z[2].im, sol[5], 1e-9, "#{desc}: z2.imag"
15
+ assert_rel z[3].re, sol[6], 1e-9, "#{desc}: z3.real"
16
+ assert_rel z[3].im, sol[7], 1e-9, "#{desc}: z3.imag"
17
+ end
18
+
19
+ def test_quartic
20
+ return unless GSL::Poly.method_defined?(:complex_solve_quartic)
21
+
22
+ sol = 3.0 / Math.sqrt(2.0)
23
+
24
+ _test_quartic(-81.0, -3.0, 0.0, 0.0, -3.0, 0.0, 3.0, 3.0, 0.0)
25
+ _test_quartic(81.0, -sol, -sol, -sol, sol, sol, -sol, sol, sol)
26
+ end
27
+
28
+ end