rb-gsl 1.15.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (660) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +6 -0
  3. data/COPYING +339 -0
  4. data/ChangeLog +567 -0
  5. data/README +32 -0
  6. data/Rakefile +99 -0
  7. data/THANKS +17 -0
  8. data/VERSION +1 -0
  9. data/examples/alf/alf.gp +15 -0
  10. data/examples/alf/alf.rb +32 -0
  11. data/examples/blas/blas.rb +13 -0
  12. data/examples/blas/dnrm2.rb +16 -0
  13. data/examples/blas/level1.rb +81 -0
  14. data/examples/blas/level2.rb +11 -0
  15. data/examples/blas/level3.rb +12 -0
  16. data/examples/bspline.rb +57 -0
  17. data/examples/cdf.rb +16 -0
  18. data/examples/cheb.rb +21 -0
  19. data/examples/combination.rb +23 -0
  20. data/examples/complex/RC-lpf.rb +47 -0
  21. data/examples/complex/add.rb +36 -0
  22. data/examples/complex/coerce.rb +14 -0
  23. data/examples/complex/complex.rb +25 -0
  24. data/examples/complex/fpmi.rb +70 -0
  25. data/examples/complex/functions.rb +77 -0
  26. data/examples/complex/michelson.rb +36 -0
  27. data/examples/complex/mul.rb +28 -0
  28. data/examples/complex/oscillator.rb +17 -0
  29. data/examples/complex/set.rb +37 -0
  30. data/examples/const/physconst.rb +151 -0
  31. data/examples/const/travel.rb +45 -0
  32. data/examples/deriv/demo.rb +13 -0
  33. data/examples/deriv/deriv.rb +36 -0
  34. data/examples/deriv/diff.rb +35 -0
  35. data/examples/dht.rb +42 -0
  36. data/examples/dirac.rb +56 -0
  37. data/examples/eigen/eigen.rb +34 -0
  38. data/examples/eigen/herm.rb +22 -0
  39. data/examples/eigen/narray.rb +9 -0
  40. data/examples/eigen/nonsymm.rb +37 -0
  41. data/examples/eigen/nonsymmv.rb +43 -0
  42. data/examples/eigen/qhoscillator.gp +35 -0
  43. data/examples/eigen/qhoscillator.rb +90 -0
  44. data/examples/eigen/vander.rb +41 -0
  45. data/examples/fft/fft.rb +17 -0
  46. data/examples/fft/fft2.rb +17 -0
  47. data/examples/fft/forward.rb +25 -0
  48. data/examples/fft/forward2.rb +26 -0
  49. data/examples/fft/radix2.rb +18 -0
  50. data/examples/fft/real-halfcomplex.rb +33 -0
  51. data/examples/fft/real-halfcomplex2.rb +30 -0
  52. data/examples/fft/realradix2.rb +19 -0
  53. data/examples/fft/sunspot.dat +256 -0
  54. data/examples/fft/sunspot.rb +16 -0
  55. data/examples/fit/expdata.dat +20 -0
  56. data/examples/fit/expfit.rb +31 -0
  57. data/examples/fit/gaussfit.rb +29 -0
  58. data/examples/fit/gaussian_2peaks.rb +34 -0
  59. data/examples/fit/hillfit.rb +40 -0
  60. data/examples/fit/lognormal.rb +26 -0
  61. data/examples/fit/lorentzfit.rb +22 -0
  62. data/examples/fit/multifit.rb +72 -0
  63. data/examples/fit/ndlinear.rb +133 -0
  64. data/examples/fit/nonlinearfit.rb +89 -0
  65. data/examples/fit/plot.gp +36 -0
  66. data/examples/fit/polyfit.rb +9 -0
  67. data/examples/fit/powerfit.rb +21 -0
  68. data/examples/fit/sigmoidfit.rb +40 -0
  69. data/examples/fit/sinfit.rb +22 -0
  70. data/examples/fit/wlinear.rb +46 -0
  71. data/examples/fresnel.rb +11 -0
  72. data/examples/function/function.rb +36 -0
  73. data/examples/function/log.rb +7 -0
  74. data/examples/function/min.rb +33 -0
  75. data/examples/function/sin.rb +10 -0
  76. data/examples/function/synchrotron.rb +18 -0
  77. data/examples/gallery/butterfly.rb +7 -0
  78. data/examples/gallery/cayley.rb +12 -0
  79. data/examples/gallery/cornu.rb +23 -0
  80. data/examples/gallery/eight.rb +11 -0
  81. data/examples/gallery/koch.rb +40 -0
  82. data/examples/gallery/lemniscate.rb +11 -0
  83. data/examples/gallery/polar.rb +11 -0
  84. data/examples/gallery/rgplot/cossin.rb +35 -0
  85. data/examples/gallery/rgplot/rgplot.replaced +0 -0
  86. data/examples/gallery/rgplot/roesller.rb +55 -0
  87. data/examples/gallery/roesller.rb +39 -0
  88. data/examples/gallery/scarabaeus.rb +14 -0
  89. data/examples/histogram/cauchy.rb +27 -0
  90. data/examples/histogram/cauchy.sh +2 -0
  91. data/examples/histogram/exponential.rb +19 -0
  92. data/examples/histogram/gauss.rb +16 -0
  93. data/examples/histogram/gsl-histogram.rb +40 -0
  94. data/examples/histogram/histo2d.rb +31 -0
  95. data/examples/histogram/histo3d.rb +34 -0
  96. data/examples/histogram/histogram-pdf.rb +27 -0
  97. data/examples/histogram/histogram.rb +26 -0
  98. data/examples/histogram/integral.rb +28 -0
  99. data/examples/histogram/poisson.rb +27 -0
  100. data/examples/histogram/power.rb +25 -0
  101. data/examples/histogram/rebin.rb +17 -0
  102. data/examples/histogram/smp.dat +5 -0
  103. data/examples/histogram/xexp.rb +21 -0
  104. data/examples/integration/ahmed.rb +21 -0
  105. data/examples/integration/cosmology.rb +75 -0
  106. data/examples/integration/friedmann.gp +16 -0
  107. data/examples/integration/friedmann.rb +35 -0
  108. data/examples/integration/gamma-zeta.rb +35 -0
  109. data/examples/integration/integration.rb +22 -0
  110. data/examples/integration/qag.rb +8 -0
  111. data/examples/integration/qag2.rb +14 -0
  112. data/examples/integration/qag3.rb +8 -0
  113. data/examples/integration/qagi.rb +28 -0
  114. data/examples/integration/qagi2.rb +49 -0
  115. data/examples/integration/qagiu.rb +29 -0
  116. data/examples/integration/qagp.rb +20 -0
  117. data/examples/integration/qags.rb +14 -0
  118. data/examples/integration/qawc.rb +18 -0
  119. data/examples/integration/qawf.rb +41 -0
  120. data/examples/integration/qawo.rb +29 -0
  121. data/examples/integration/qaws.rb +30 -0
  122. data/examples/integration/qng.rb +17 -0
  123. data/examples/interp/demo.gp +20 -0
  124. data/examples/interp/demo.rb +45 -0
  125. data/examples/interp/interp.rb +37 -0
  126. data/examples/interp/points +10 -0
  127. data/examples/interp/spline.rb +20 -0
  128. data/examples/jacobi/deriv.rb +40 -0
  129. data/examples/jacobi/integrate.rb +34 -0
  130. data/examples/jacobi/interp.rb +43 -0
  131. data/examples/jacobi/jacobi.rb +11 -0
  132. data/examples/linalg/HH.rb +15 -0
  133. data/examples/linalg/HH_narray.rb +13 -0
  134. data/examples/linalg/LQ_solve.rb +73 -0
  135. data/examples/linalg/LU.rb +84 -0
  136. data/examples/linalg/LU2.rb +31 -0
  137. data/examples/linalg/LU_narray.rb +24 -0
  138. data/examples/linalg/PTLQ.rb +47 -0
  139. data/examples/linalg/QR.rb +18 -0
  140. data/examples/linalg/QRPT.rb +47 -0
  141. data/examples/linalg/QR_solve.rb +78 -0
  142. data/examples/linalg/QR_solve_narray.rb +13 -0
  143. data/examples/linalg/SV.rb +16 -0
  144. data/examples/linalg/SV_narray.rb +12 -0
  145. data/examples/linalg/SV_solve.rb +49 -0
  146. data/examples/linalg/chol.rb +29 -0
  147. data/examples/linalg/chol_narray.rb +15 -0
  148. data/examples/linalg/complex.rb +57 -0
  149. data/examples/linalg/invert_narray.rb +10 -0
  150. data/examples/math/const.rb +67 -0
  151. data/examples/math/elementary.rb +35 -0
  152. data/examples/math/functions.rb +41 -0
  153. data/examples/math/inf_nan.rb +34 -0
  154. data/examples/math/minmax.rb +22 -0
  155. data/examples/math/power.rb +18 -0
  156. data/examples/math/test.rb +31 -0
  157. data/examples/matrix/a.dat +0 -0
  158. data/examples/matrix/add.rb +45 -0
  159. data/examples/matrix/b.dat +4 -0
  160. data/examples/matrix/cat.rb +31 -0
  161. data/examples/matrix/colvectors.rb +24 -0
  162. data/examples/matrix/complex.rb +41 -0
  163. data/examples/matrix/det.rb +29 -0
  164. data/examples/matrix/diagonal.rb +23 -0
  165. data/examples/matrix/get_all.rb +159 -0
  166. data/examples/matrix/hilbert.rb +31 -0
  167. data/examples/matrix/iterator.rb +19 -0
  168. data/examples/matrix/matrix.rb +57 -0
  169. data/examples/matrix/minmax.rb +53 -0
  170. data/examples/matrix/mul.rb +39 -0
  171. data/examples/matrix/rand.rb +20 -0
  172. data/examples/matrix/read.rb +29 -0
  173. data/examples/matrix/rowcol.rb +47 -0
  174. data/examples/matrix/set.rb +41 -0
  175. data/examples/matrix/set_all.rb +100 -0
  176. data/examples/matrix/view.rb +32 -0
  177. data/examples/matrix/view_all.rb +148 -0
  178. data/examples/matrix/write.rb +23 -0
  179. data/examples/min.rb +29 -0
  180. data/examples/monte/miser.rb +47 -0
  181. data/examples/monte/monte.rb +47 -0
  182. data/examples/monte/plain.rb +47 -0
  183. data/examples/monte/vegas.rb +46 -0
  184. data/examples/multimin/bundle.rb +66 -0
  185. data/examples/multimin/cqp.rb +109 -0
  186. data/examples/multimin/fdfminimizer.rb +40 -0
  187. data/examples/multimin/fminimizer.rb +41 -0
  188. data/examples/multiroot/demo.rb +36 -0
  189. data/examples/multiroot/fdfsolver.rb +50 -0
  190. data/examples/multiroot/fsolver.rb +33 -0
  191. data/examples/multiroot/fsolver2.rb +32 -0
  192. data/examples/multiroot/fsolver3.rb +26 -0
  193. data/examples/narray/histogram.rb +14 -0
  194. data/examples/narray/mandel.rb +27 -0
  195. data/examples/narray/narray.rb +28 -0
  196. data/examples/narray/narray2.rb +44 -0
  197. data/examples/narray/sf.rb +26 -0
  198. data/examples/ntuple/create.rb +17 -0
  199. data/examples/ntuple/project.rb +31 -0
  200. data/examples/odeiv/binarysystem.gp +23 -0
  201. data/examples/odeiv/binarysystem.rb +104 -0
  202. data/examples/odeiv/demo.gp +24 -0
  203. data/examples/odeiv/demo.rb +69 -0
  204. data/examples/odeiv/demo2.gp +26 -0
  205. data/examples/odeiv/duffing.rb +45 -0
  206. data/examples/odeiv/frei1.rb +109 -0
  207. data/examples/odeiv/frei2.rb +76 -0
  208. data/examples/odeiv/legendre.rb +52 -0
  209. data/examples/odeiv/odeiv.rb +32 -0
  210. data/examples/odeiv/odeiv2.rb +45 -0
  211. data/examples/odeiv/oscillator.rb +42 -0
  212. data/examples/odeiv/sedov.rb +97 -0
  213. data/examples/odeiv/whitedwarf.gp +40 -0
  214. data/examples/odeiv/whitedwarf.rb +158 -0
  215. data/examples/ool/conmin.rb +100 -0
  216. data/examples/ool/gencan.rb +99 -0
  217. data/examples/ool/pgrad.rb +100 -0
  218. data/examples/ool/spg.rb +100 -0
  219. data/examples/pdf/bernoulli.rb +5 -0
  220. data/examples/pdf/beta.rb +7 -0
  221. data/examples/pdf/binomiral.rb +10 -0
  222. data/examples/pdf/cauchy.rb +6 -0
  223. data/examples/pdf/chisq.rb +8 -0
  224. data/examples/pdf/exponential.rb +7 -0
  225. data/examples/pdf/exppow.rb +6 -0
  226. data/examples/pdf/fdist.rb +7 -0
  227. data/examples/pdf/flat.rb +7 -0
  228. data/examples/pdf/gamma.rb +8 -0
  229. data/examples/pdf/gauss-tail.rb +5 -0
  230. data/examples/pdf/gauss.rb +6 -0
  231. data/examples/pdf/geometric.rb +5 -0
  232. data/examples/pdf/gumbel.rb +6 -0
  233. data/examples/pdf/hypergeometric.rb +11 -0
  234. data/examples/pdf/landau.rb +5 -0
  235. data/examples/pdf/laplace.rb +7 -0
  236. data/examples/pdf/logarithmic.rb +5 -0
  237. data/examples/pdf/logistic.rb +6 -0
  238. data/examples/pdf/lognormal.rb +6 -0
  239. data/examples/pdf/neg-binomiral.rb +10 -0
  240. data/examples/pdf/pareto.rb +7 -0
  241. data/examples/pdf/pascal.rb +10 -0
  242. data/examples/pdf/poisson.rb +5 -0
  243. data/examples/pdf/rayleigh-tail.rb +6 -0
  244. data/examples/pdf/rayleigh.rb +6 -0
  245. data/examples/pdf/tdist.rb +6 -0
  246. data/examples/pdf/weibull.rb +8 -0
  247. data/examples/permutation/ex1.rb +22 -0
  248. data/examples/permutation/permutation.rb +16 -0
  249. data/examples/poly/bell.rb +6 -0
  250. data/examples/poly/bessel.rb +6 -0
  251. data/examples/poly/cheb.rb +6 -0
  252. data/examples/poly/cheb_II.rb +6 -0
  253. data/examples/poly/cubic.rb +9 -0
  254. data/examples/poly/demo.rb +20 -0
  255. data/examples/poly/eval.rb +28 -0
  256. data/examples/poly/eval_derivs.rb +14 -0
  257. data/examples/poly/fit.rb +21 -0
  258. data/examples/poly/hermite.rb +6 -0
  259. data/examples/poly/poly.rb +13 -0
  260. data/examples/poly/quadratic.rb +25 -0
  261. data/examples/random/diffusion.rb +34 -0
  262. data/examples/random/gaussian.rb +9 -0
  263. data/examples/random/generator.rb +27 -0
  264. data/examples/random/hdsobol.rb +21 -0
  265. data/examples/random/poisson.rb +9 -0
  266. data/examples/random/qrng.rb +19 -0
  267. data/examples/random/randomwalk.rb +37 -0
  268. data/examples/random/randomwalk2d.rb +19 -0
  269. data/examples/random/rayleigh.rb +36 -0
  270. data/examples/random/rng.rb +33 -0
  271. data/examples/random/rngextra.rb +14 -0
  272. data/examples/roots/bisection.rb +25 -0
  273. data/examples/roots/brent.rb +43 -0
  274. data/examples/roots/demo.rb +30 -0
  275. data/examples/roots/newton.rb +46 -0
  276. data/examples/roots/recombination.gp +12 -0
  277. data/examples/roots/recombination.rb +61 -0
  278. data/examples/roots/steffenson.rb +48 -0
  279. data/examples/sf/ShiChi.rb +6 -0
  280. data/examples/sf/SiCi.rb +6 -0
  281. data/examples/sf/airy_Ai.rb +8 -0
  282. data/examples/sf/airy_Bi.rb +8 -0
  283. data/examples/sf/bessel_IK.rb +12 -0
  284. data/examples/sf/bessel_JY.rb +13 -0
  285. data/examples/sf/beta_inc.rb +9 -0
  286. data/examples/sf/clausen.rb +6 -0
  287. data/examples/sf/dawson.rb +5 -0
  288. data/examples/sf/debye.rb +9 -0
  289. data/examples/sf/dilog.rb +6 -0
  290. data/examples/sf/ellint.rb +6 -0
  291. data/examples/sf/expint.rb +8 -0
  292. data/examples/sf/fermi.rb +10 -0
  293. data/examples/sf/gamma_inc_P.rb +9 -0
  294. data/examples/sf/gegenbauer.rb +8 -0
  295. data/examples/sf/hyperg.rb +7 -0
  296. data/examples/sf/laguerre.rb +19 -0
  297. data/examples/sf/lambertW.rb +5 -0
  298. data/examples/sf/legendre_P.rb +10 -0
  299. data/examples/sf/lngamma.rb +5 -0
  300. data/examples/sf/psi.rb +54 -0
  301. data/examples/sf/sphbessel.gp +27 -0
  302. data/examples/sf/sphbessel.rb +30 -0
  303. data/examples/sf/synchrotron.rb +5 -0
  304. data/examples/sf/transport.rb +10 -0
  305. data/examples/sf/zetam1.rb +5 -0
  306. data/examples/siman.rb +44 -0
  307. data/examples/sort/heapsort.rb +23 -0
  308. data/examples/sort/heapsort_vector_complex.rb +21 -0
  309. data/examples/sort/sort.rb +23 -0
  310. data/examples/sort/sort2.rb +16 -0
  311. data/examples/stats/mean.rb +17 -0
  312. data/examples/stats/statistics.rb +18 -0
  313. data/examples/stats/test.rb +9 -0
  314. data/examples/sum.rb +34 -0
  315. data/examples/tamu_anova.rb +18 -0
  316. data/examples/vector/a.dat +0 -0
  317. data/examples/vector/add.rb +56 -0
  318. data/examples/vector/b.dat +4 -0
  319. data/examples/vector/c.dat +3 -0
  320. data/examples/vector/collect.rb +26 -0
  321. data/examples/vector/compare.rb +28 -0
  322. data/examples/vector/complex.rb +51 -0
  323. data/examples/vector/complex_get_all.rb +85 -0
  324. data/examples/vector/complex_set_all.rb +131 -0
  325. data/examples/vector/complex_view_all.rb +77 -0
  326. data/examples/vector/connect.rb +22 -0
  327. data/examples/vector/decimate.rb +38 -0
  328. data/examples/vector/diff.rb +31 -0
  329. data/examples/vector/filescan.rb +17 -0
  330. data/examples/vector/floor.rb +23 -0
  331. data/examples/vector/get_all.rb +82 -0
  332. data/examples/vector/gnuplot.rb +38 -0
  333. data/examples/vector/graph.rb +28 -0
  334. data/examples/vector/histogram.rb +22 -0
  335. data/examples/vector/linspace.rb +24 -0
  336. data/examples/vector/log.rb +17 -0
  337. data/examples/vector/logic.rb +33 -0
  338. data/examples/vector/logspace.rb +25 -0
  339. data/examples/vector/minmax.rb +47 -0
  340. data/examples/vector/mul.rb +49 -0
  341. data/examples/vector/narray.rb +46 -0
  342. data/examples/vector/read.rb +29 -0
  343. data/examples/vector/set.rb +35 -0
  344. data/examples/vector/set_all.rb +121 -0
  345. data/examples/vector/smpv.dat +15 -0
  346. data/examples/vector/test.rb +43 -0
  347. data/examples/vector/test_gslblock.rb +58 -0
  348. data/examples/vector/vector.rb +110 -0
  349. data/examples/vector/view.rb +35 -0
  350. data/examples/vector/view_all.rb +73 -0
  351. data/examples/vector/where.rb +29 -0
  352. data/examples/vector/write.rb +24 -0
  353. data/examples/vector/zip.rb +34 -0
  354. data/examples/wavelet/ecg.dat +256 -0
  355. data/examples/wavelet/wavelet1.rb +50 -0
  356. data/ext/alf.c +206 -0
  357. data/ext/array.c +642 -0
  358. data/ext/array_complex.c +248 -0
  359. data/ext/blas.c +29 -0
  360. data/ext/blas1.c +734 -0
  361. data/ext/blas2.c +1093 -0
  362. data/ext/blas3.c +881 -0
  363. data/ext/block.c +44 -0
  364. data/ext/block_source.c +887 -0
  365. data/ext/bspline.c +130 -0
  366. data/ext/bundle.c +3 -0
  367. data/ext/cdf.c +754 -0
  368. data/ext/cheb.c +542 -0
  369. data/ext/combination.c +283 -0
  370. data/ext/common.c +325 -0
  371. data/ext/complex.c +1004 -0
  372. data/ext/const.c +673 -0
  373. data/ext/const_additional.c +120 -0
  374. data/ext/cqp.c +283 -0
  375. data/ext/deriv.c +195 -0
  376. data/ext/dht.c +361 -0
  377. data/ext/diff.c +166 -0
  378. data/ext/dirac.c +389 -0
  379. data/ext/eigen.c +2373 -0
  380. data/ext/error.c +193 -0
  381. data/ext/extconf.rb +303 -0
  382. data/ext/fcmp.c +66 -0
  383. data/ext/fft.c +1102 -0
  384. data/ext/fit.c +205 -0
  385. data/ext/fresnel.c +312 -0
  386. data/ext/function.c +524 -0
  387. data/ext/geometry.c +139 -0
  388. data/ext/graph.c +1640 -0
  389. data/ext/gsl.c +280 -0
  390. data/ext/gsl_narray.c +804 -0
  391. data/ext/histogram.c +1991 -0
  392. data/ext/histogram2d.c +1068 -0
  393. data/ext/histogram3d.c +884 -0
  394. data/ext/histogram3d_source.c +750 -0
  395. data/ext/histogram_find.c +101 -0
  396. data/ext/histogram_oper.c +159 -0
  397. data/ext/ieee.c +100 -0
  398. data/ext/integration.c +1179 -0
  399. data/ext/interp.c +512 -0
  400. data/ext/jacobi.c +739 -0
  401. data/ext/linalg.c +4042 -0
  402. data/ext/linalg_complex.c +739 -0
  403. data/ext/math.c +725 -0
  404. data/ext/matrix.c +39 -0
  405. data/ext/matrix_complex.c +1737 -0
  406. data/ext/matrix_double.c +560 -0
  407. data/ext/matrix_int.c +256 -0
  408. data/ext/matrix_source.c +2734 -0
  409. data/ext/min.c +250 -0
  410. data/ext/monte.c +992 -0
  411. data/ext/multifit.c +1871 -0
  412. data/ext/multimin.c +806 -0
  413. data/ext/multimin_fsdf.c +156 -0
  414. data/ext/multiroots.c +955 -0
  415. data/ext/multiset.c +214 -0
  416. data/ext/ndlinear.c +321 -0
  417. data/ext/nmf.c +171 -0
  418. data/ext/nmf_wrap.c +75 -0
  419. data/ext/ntuple.c +469 -0
  420. data/ext/odeiv.c +962 -0
  421. data/ext/ool.c +879 -0
  422. data/ext/oper_complex_source.c +253 -0
  423. data/ext/permutation.c +596 -0
  424. data/ext/poly.c +42 -0
  425. data/ext/poly2.c +265 -0
  426. data/ext/poly_source.c +1915 -0
  427. data/ext/qrng.c +171 -0
  428. data/ext/randist.c +1873 -0
  429. data/ext/rational.c +480 -0
  430. data/ext/rng.c +612 -0
  431. data/ext/root.c +408 -0
  432. data/ext/sf.c +1494 -0
  433. data/ext/sf_airy.c +200 -0
  434. data/ext/sf_bessel.c +871 -0
  435. data/ext/sf_clausen.c +28 -0
  436. data/ext/sf_coulomb.c +206 -0
  437. data/ext/sf_coupling.c +121 -0
  438. data/ext/sf_dawson.c +29 -0
  439. data/ext/sf_debye.c +157 -0
  440. data/ext/sf_dilog.c +43 -0
  441. data/ext/sf_elementary.c +46 -0
  442. data/ext/sf_ellint.c +206 -0
  443. data/ext/sf_elljac.c +30 -0
  444. data/ext/sf_erfc.c +93 -0
  445. data/ext/sf_exp.c +169 -0
  446. data/ext/sf_expint.c +211 -0
  447. data/ext/sf_fermi_dirac.c +148 -0
  448. data/ext/sf_gamma.c +347 -0
  449. data/ext/sf_gegenbauer.c +97 -0
  450. data/ext/sf_hyperg.c +203 -0
  451. data/ext/sf_laguerre.c +113 -0
  452. data/ext/sf_lambert.c +47 -0
  453. data/ext/sf_legendre.c +368 -0
  454. data/ext/sf_log.c +105 -0
  455. data/ext/sf_mathieu.c +238 -0
  456. data/ext/sf_power.c +47 -0
  457. data/ext/sf_psi.c +98 -0
  458. data/ext/sf_synchrotron.c +48 -0
  459. data/ext/sf_transport.c +76 -0
  460. data/ext/sf_trigonometric.c +210 -0
  461. data/ext/sf_zeta.c +119 -0
  462. data/ext/signal.c +308 -0
  463. data/ext/siman.c +717 -0
  464. data/ext/sort.c +208 -0
  465. data/ext/spline.c +395 -0
  466. data/ext/stats.c +800 -0
  467. data/ext/sum.c +168 -0
  468. data/ext/tamu_anova.c +56 -0
  469. data/ext/tensor.c +38 -0
  470. data/ext/tensor_source.c +1123 -0
  471. data/ext/vector.c +38 -0
  472. data/ext/vector_complex.c +2246 -0
  473. data/ext/vector_double.c +1438 -0
  474. data/ext/vector_int.c +204 -0
  475. data/ext/vector_source.c +3336 -0
  476. data/ext/wavelet.c +945 -0
  477. data/include/rb_gsl.h +158 -0
  478. data/include/rb_gsl_array.h +238 -0
  479. data/include/rb_gsl_cheb.h +21 -0
  480. data/include/rb_gsl_common.h +348 -0
  481. data/include/rb_gsl_complex.h +25 -0
  482. data/include/rb_gsl_config.h +62 -0
  483. data/include/rb_gsl_const.h +29 -0
  484. data/include/rb_gsl_dirac.h +13 -0
  485. data/include/rb_gsl_eigen.h +17 -0
  486. data/include/rb_gsl_fft.h +62 -0
  487. data/include/rb_gsl_fit.h +25 -0
  488. data/include/rb_gsl_function.h +27 -0
  489. data/include/rb_gsl_graph.h +70 -0
  490. data/include/rb_gsl_histogram.h +63 -0
  491. data/include/rb_gsl_histogram3d.h +97 -0
  492. data/include/rb_gsl_integration.h +17 -0
  493. data/include/rb_gsl_interp.h +46 -0
  494. data/include/rb_gsl_linalg.h +25 -0
  495. data/include/rb_gsl_math.h +26 -0
  496. data/include/rb_gsl_odeiv.h +21 -0
  497. data/include/rb_gsl_poly.h +71 -0
  498. data/include/rb_gsl_rational.h +37 -0
  499. data/include/rb_gsl_rng.h +21 -0
  500. data/include/rb_gsl_root.h +22 -0
  501. data/include/rb_gsl_sf.h +119 -0
  502. data/include/rb_gsl_statistics.h +17 -0
  503. data/include/rb_gsl_tensor.h +45 -0
  504. data/include/rb_gsl_with_narray.h +29 -0
  505. data/include/templates_off.h +87 -0
  506. data/include/templates_on.h +241 -0
  507. data/lib/gsl.rb +3 -0
  508. data/lib/gsl/gnuplot.rb +41 -0
  509. data/lib/gsl/oper.rb +68 -0
  510. data/lib/ool.rb +22 -0
  511. data/lib/ool/conmin.rb +30 -0
  512. data/lib/rbgsl.rb +3 -0
  513. data/rdoc/alf.rdoc +77 -0
  514. data/rdoc/blas.rdoc +269 -0
  515. data/rdoc/bspline.rdoc +42 -0
  516. data/rdoc/changes.rdoc +164 -0
  517. data/rdoc/cheb.rdoc +99 -0
  518. data/rdoc/cholesky_complex.rdoc +46 -0
  519. data/rdoc/combi.rdoc +125 -0
  520. data/rdoc/complex.rdoc +210 -0
  521. data/rdoc/const.rdoc +546 -0
  522. data/rdoc/dht.rdoc +122 -0
  523. data/rdoc/diff.rdoc +133 -0
  524. data/rdoc/ehandling.rdoc +50 -0
  525. data/rdoc/eigen.rdoc +401 -0
  526. data/rdoc/fft.rdoc +535 -0
  527. data/rdoc/fit.rdoc +284 -0
  528. data/rdoc/function.rdoc +94 -0
  529. data/rdoc/graph.rdoc +137 -0
  530. data/rdoc/hist.rdoc +409 -0
  531. data/rdoc/hist2d.rdoc +279 -0
  532. data/rdoc/hist3d.rdoc +112 -0
  533. data/rdoc/index.rdoc +62 -0
  534. data/rdoc/integration.rdoc +398 -0
  535. data/rdoc/interp.rdoc +231 -0
  536. data/rdoc/intro.rdoc +27 -0
  537. data/rdoc/linalg.rdoc +681 -0
  538. data/rdoc/linalg_complex.rdoc +88 -0
  539. data/rdoc/math.rdoc +276 -0
  540. data/rdoc/matrix.rdoc +1093 -0
  541. data/rdoc/min.rdoc +189 -0
  542. data/rdoc/monte.rdoc +234 -0
  543. data/rdoc/multimin.rdoc +312 -0
  544. data/rdoc/multiroot.rdoc +293 -0
  545. data/rdoc/narray.rdoc +177 -0
  546. data/rdoc/ndlinear.rdoc +250 -0
  547. data/rdoc/nonlinearfit.rdoc +348 -0
  548. data/rdoc/ntuple.rdoc +88 -0
  549. data/rdoc/odeiv.rdoc +378 -0
  550. data/rdoc/perm.rdoc +221 -0
  551. data/rdoc/poly.rdoc +335 -0
  552. data/rdoc/qrng.rdoc +90 -0
  553. data/rdoc/randist.rdoc +233 -0
  554. data/rdoc/ref.rdoc +93 -0
  555. data/rdoc/rng.rdoc +203 -0
  556. data/rdoc/rngextra.rdoc +11 -0
  557. data/rdoc/roots.rdoc +305 -0
  558. data/rdoc/screenshot.rdoc +40 -0
  559. data/rdoc/sf.rdoc +1622 -0
  560. data/rdoc/siman.rdoc +89 -0
  561. data/rdoc/sort.rdoc +94 -0
  562. data/rdoc/start.rdoc +16 -0
  563. data/rdoc/stats.rdoc +219 -0
  564. data/rdoc/sum.rdoc +65 -0
  565. data/rdoc/tensor.rdoc +251 -0
  566. data/rdoc/tut.rdoc +5 -0
  567. data/rdoc/use.rdoc +177 -0
  568. data/rdoc/vector.rdoc +1243 -0
  569. data/rdoc/vector_complex.rdoc +347 -0
  570. data/rdoc/wavelet.rdoc +218 -0
  571. data/setup.rb +1585 -0
  572. data/tests/blas/amax.rb +14 -0
  573. data/tests/blas/asum.rb +16 -0
  574. data/tests/blas/axpy.rb +25 -0
  575. data/tests/blas/copy.rb +23 -0
  576. data/tests/blas/dot.rb +23 -0
  577. data/tests/bspline.rb +53 -0
  578. data/tests/cdf.rb +1388 -0
  579. data/tests/cheb.rb +112 -0
  580. data/tests/combination.rb +123 -0
  581. data/tests/complex.rb +17 -0
  582. data/tests/const.rb +24 -0
  583. data/tests/deriv.rb +85 -0
  584. data/tests/dht/dht1.rb +17 -0
  585. data/tests/dht/dht2.rb +23 -0
  586. data/tests/dht/dht3.rb +23 -0
  587. data/tests/dht/dht4.rb +23 -0
  588. data/tests/diff.rb +78 -0
  589. data/tests/eigen/eigen.rb +220 -0
  590. data/tests/eigen/gen.rb +105 -0
  591. data/tests/eigen/genherm.rb +66 -0
  592. data/tests/eigen/gensymm.rb +68 -0
  593. data/tests/eigen/nonsymm.rb +53 -0
  594. data/tests/eigen/nonsymmv.rb +53 -0
  595. data/tests/eigen/symm-herm.rb +74 -0
  596. data/tests/err.rb +58 -0
  597. data/tests/fit.rb +124 -0
  598. data/tests/gsl_test.rb +118 -0
  599. data/tests/gsl_test2.rb +110 -0
  600. data/tests/histo.rb +12 -0
  601. data/tests/integration/integration1.rb +72 -0
  602. data/tests/integration/integration2.rb +71 -0
  603. data/tests/integration/integration3.rb +71 -0
  604. data/tests/integration/integration4.rb +71 -0
  605. data/tests/interp.rb +45 -0
  606. data/tests/linalg/HH.rb +64 -0
  607. data/tests/linalg/LU.rb +47 -0
  608. data/tests/linalg/QR.rb +77 -0
  609. data/tests/linalg/SV.rb +24 -0
  610. data/tests/linalg/TDN.rb +116 -0
  611. data/tests/linalg/TDS.rb +122 -0
  612. data/tests/linalg/bidiag.rb +73 -0
  613. data/tests/linalg/cholesky.rb +20 -0
  614. data/tests/linalg/linalg.rb +158 -0
  615. data/tests/matrix/matrix_complex_test.rb +36 -0
  616. data/tests/matrix/matrix_nmf_test.rb +39 -0
  617. data/tests/matrix/matrix_test.rb +48 -0
  618. data/tests/min.rb +99 -0
  619. data/tests/monte/miser.rb +31 -0
  620. data/tests/monte/vegas.rb +45 -0
  621. data/tests/multifit/test_2dgauss.rb +112 -0
  622. data/tests/multifit/test_brown.rb +90 -0
  623. data/tests/multifit/test_enso.rb +246 -0
  624. data/tests/multifit/test_filip.rb +155 -0
  625. data/tests/multifit/test_gauss.rb +97 -0
  626. data/tests/multifit/test_longley.rb +110 -0
  627. data/tests/multifit/test_multifit.rb +52 -0
  628. data/tests/multimin.rb +139 -0
  629. data/tests/multiroot.rb +131 -0
  630. data/tests/multiset.rb +52 -0
  631. data/tests/narray/blas_dnrm2.rb +20 -0
  632. data/tests/odeiv.rb +353 -0
  633. data/tests/poly/poly.rb +290 -0
  634. data/tests/poly/special.rb +65 -0
  635. data/tests/qrng.rb +131 -0
  636. data/tests/quartic.rb +29 -0
  637. data/tests/randist.rb +134 -0
  638. data/tests/rng.rb +305 -0
  639. data/tests/roots.rb +76 -0
  640. data/tests/run-test.sh +17 -0
  641. data/tests/sf/gsl_test_sf.rb +249 -0
  642. data/tests/sf/test_airy.rb +83 -0
  643. data/tests/sf/test_bessel.rb +306 -0
  644. data/tests/sf/test_coulomb.rb +17 -0
  645. data/tests/sf/test_dilog.rb +25 -0
  646. data/tests/sf/test_gamma.rb +209 -0
  647. data/tests/sf/test_hyperg.rb +356 -0
  648. data/tests/sf/test_legendre.rb +227 -0
  649. data/tests/sf/test_mathieu.rb +59 -0
  650. data/tests/sf/test_mode.rb +19 -0
  651. data/tests/sf/test_sf.rb +839 -0
  652. data/tests/stats.rb +174 -0
  653. data/tests/stats_mt.rb +16 -0
  654. data/tests/sum.rb +98 -0
  655. data/tests/sys.rb +323 -0
  656. data/tests/tensor.rb +419 -0
  657. data/tests/vector/vector_complex_test.rb +101 -0
  658. data/tests/vector/vector_test.rb +141 -0
  659. data/tests/wavelet.rb +142 -0
  660. metadata +789 -0
@@ -0,0 +1,42 @@
1
+ /*
2
+ poly.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+ #include "rb_gsl_config.h"
12
+ #include "rb_gsl_poly.h"
13
+ #include "rb_gsl_array.h"
14
+ #include "rb_gsl_common.h"
15
+ #ifdef HAVE_NARARY_H
16
+ #include "narray.h"
17
+ #endif
18
+
19
+ void Init_gsl_poly_init(VALUE module);
20
+ void Init_gsl_poly_int_init(VALUE module);
21
+ void Init_gsl_poly2(VALUE module);
22
+
23
+ #define BASE_DOUBLE
24
+ #include "templates_on.h"
25
+ #include "poly_source.c"
26
+ #include "templates_off.h"
27
+ void Init_gsl_poly(VALUE module)
28
+ {
29
+ Init_gsl_poly_init(module);
30
+ }
31
+
32
+ #undef BASE_DOUBLE
33
+
34
+ #define BASE_INT
35
+ #include "templates_on.h"
36
+ #include "poly_source.c"
37
+ #include "templates_off.h"
38
+ void Init_gsl_poly_int(VALUE module)
39
+ {
40
+ Init_gsl_poly_int_init(module);
41
+ }
42
+ #undef BASE_INT
@@ -0,0 +1,265 @@
1
+ /*
2
+ poly2.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2004 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+ #include "rb_gsl_config.h"
12
+ #include "rb_gsl_poly.h"
13
+ #include "rb_gsl_math.h"
14
+ #include "rb_gsl_array.h"
15
+ #include <gsl/gsl_sf_gamma.h>
16
+
17
+ static gsl_poly_int* mygsl_poly_hermite(int n1)
18
+ {
19
+ size_t n;
20
+ gsl_vector_int *p1, *p2, *p0;
21
+ int coef1[2] = {0, 2};
22
+ int coef2[3] = {-2, 0, 4};
23
+ if (n1 < 0) rb_raise(rb_eArgError, "order must be >= 0");
24
+ p0 = gsl_vector_int_calloc(n1 + 1);
25
+ switch (n1) {
26
+ case 0:
27
+ gsl_vector_int_set(p0, 0, 1);
28
+ break;
29
+ case 1:
30
+ memcpy(p0->data, coef1, 2*sizeof(int));
31
+ break;
32
+ case 2:
33
+ memcpy(p0->data, coef2, 3*sizeof(int));
34
+ break;
35
+ default:
36
+ p1 = gsl_vector_int_calloc(n1 + 1);
37
+ p2 = gsl_vector_int_calloc(n1 + 1);
38
+ memcpy(p1->data, coef2, 3*sizeof(int));
39
+ memcpy(p2->data, coef1, 2*sizeof(int));
40
+ for (n = 2; n < n1; n++) {
41
+ gsl_vector_int_memcpy(p0, p1);
42
+ mygsl_vector_int_shift_scale2(p0, n);
43
+ gsl_vector_int_scale(p2, 2*n);
44
+
45
+ gsl_vector_int_sub(p0, p2);
46
+ /* save for the next iteration */
47
+ gsl_vector_int_memcpy(p2, p1);
48
+ gsl_vector_int_memcpy(p1, p0);
49
+ }
50
+ gsl_vector_int_free(p2);
51
+ gsl_vector_int_free(p1);
52
+ break;
53
+ }
54
+ return p0;
55
+ }
56
+
57
+ static gsl_poly_int* mygsl_poly_cheb(int n1)
58
+ {
59
+ size_t n;
60
+ gsl_vector_int *p1, *p2, *p0;
61
+ int coef1[2] = {0, 1};
62
+ int coef2[3] = {-1, 0, 2};
63
+ if (n1 < 0) rb_raise(rb_eArgError, "order must be >= 0");
64
+ p0 = gsl_vector_int_calloc(n1 + 1);
65
+ switch (n1) {
66
+ case 0:
67
+ gsl_vector_int_set(p0, 0, 1);
68
+ break;
69
+ case 1:
70
+ memcpy(p0->data, coef1, 2*sizeof(int));
71
+ break;
72
+ case 2:
73
+ memcpy(p0->data, coef2, 3*sizeof(int));
74
+ break;
75
+ default:
76
+ p1 = gsl_vector_int_calloc(n1 + 1);
77
+ p2 = gsl_vector_int_calloc(n1 + 1);
78
+ memcpy(p1->data, coef2, 3*sizeof(int));
79
+ memcpy(p2->data, coef1, 2*sizeof(int));
80
+ for (n = 2; n < n1; n++) {
81
+ gsl_vector_int_memcpy(p0, p1);
82
+ mygsl_vector_int_shift_scale2(p0, n);
83
+
84
+ gsl_vector_int_sub(p0, p2);
85
+ /* save for the next iteration */
86
+ gsl_vector_int_memcpy(p2, p1);
87
+ gsl_vector_int_memcpy(p1, p0);
88
+ }
89
+ gsl_vector_int_free(p2);
90
+ gsl_vector_int_free(p1);
91
+ break;
92
+ }
93
+ return p0;
94
+ }
95
+
96
+ static gsl_poly_int* mygsl_poly_chebII(int n1)
97
+ {
98
+ size_t n;
99
+ gsl_vector_int *p1, *p2, *p0;
100
+ int coef1[2] = {0, 2};
101
+ int coef2[3] = {-1, 0, 4};
102
+ if (n1 < 0) rb_raise(rb_eArgError, "order must be >= 0");
103
+ p0 = gsl_vector_int_calloc(n1 + 1);
104
+ switch (n1) {
105
+ case 0:
106
+ gsl_vector_int_set(p0, 0, 1);
107
+ break;
108
+ case 1:
109
+ memcpy(p0->data, coef1, 2*sizeof(int));
110
+ break;
111
+ case 2:
112
+ memcpy(p0->data, coef2, 3*sizeof(int));
113
+ break;
114
+ default:
115
+ p1 = gsl_vector_int_calloc(n1 + 1);
116
+ p2 = gsl_vector_int_calloc(n1 + 1);
117
+ memcpy(p1->data, coef2, 3*sizeof(int));
118
+ memcpy(p2->data, coef1, 2*sizeof(int));
119
+ for (n = 2; n < n1; n++) {
120
+ gsl_vector_int_memcpy(p0, p1);
121
+ mygsl_vector_int_shift_scale2(p0, n);
122
+ gsl_vector_int_sub(p0, p2);
123
+ /* save for the next iteration */
124
+ gsl_vector_int_memcpy(p2, p1);
125
+ gsl_vector_int_memcpy(p1, p0);
126
+ }
127
+ gsl_vector_int_free(p2);
128
+ gsl_vector_int_free(p1);
129
+ break;
130
+ }
131
+ return p0;
132
+ }
133
+
134
+ static gsl_poly_int* mygsl_poly_laguerre(int n)
135
+ {
136
+ size_t m, k;
137
+ int val;
138
+ gsl_vector_int *p0;
139
+ if (n < 0) rb_raise(rb_eArgError, "order must be >= 0");
140
+ p0 = gsl_vector_int_calloc(n + 1);
141
+ switch (n) {
142
+ case 0:
143
+ gsl_vector_int_set(p0, 0, 1);
144
+ break;
145
+ case 1:
146
+ gsl_vector_int_set(p0, 0, 1);
147
+ gsl_vector_int_set(p0, 1, -1);
148
+ break;
149
+ default:
150
+ k = gsl_sf_fact(n);
151
+ for (m = 0; m <= n; m++) {
152
+ val = k*k/gsl_sf_fact(n-m)/gsl_pow_2(gsl_sf_fact(m));
153
+ if (m%2 == 1) val *= -1;
154
+ gsl_vector_int_set(p0, m, val);
155
+ }
156
+ break;
157
+ }
158
+ return p0;
159
+ }
160
+
161
+ static gsl_poly_int* mygsl_poly_bessel(int n)
162
+ {
163
+ size_t k;
164
+ gsl_vector_int *p0;
165
+ if (n < 0) rb_raise(rb_eArgError, "order must be >= 0");
166
+ p0 = gsl_vector_int_calloc(n + 1);
167
+ for (k = 0; k <= n; k++) {
168
+ gsl_vector_int_set(p0, k, gsl_sf_fact(n+k)/gsl_sf_fact(n-k)/gsl_sf_fact(k)/((int) pow(2, k)));
169
+ }
170
+ return p0;
171
+ }
172
+
173
+ static gsl_poly_int* mygsl_poly_bell(int n1)
174
+ {
175
+ size_t n, j;
176
+ gsl_vector_int *p1, *p0;
177
+ int coef1[2] = {0, 1};
178
+ int coef2[3] = {0, 1, 1};
179
+ if (n1 < 0) rb_raise(rb_eArgError, "order must be >= 0");
180
+ p0 = gsl_vector_int_calloc(n1 + 1);
181
+ switch (n1) {
182
+ case 0:
183
+ gsl_vector_int_set(p0, 0, 1);
184
+ break;
185
+ case 1:
186
+ memcpy(p0->data, coef1, 2*sizeof(int));
187
+ break;
188
+ case 2:
189
+ memcpy(p0->data, coef2, 3*sizeof(int));
190
+ break;
191
+ default:
192
+ p1 = gsl_vector_int_calloc(n1 + 1);
193
+ memcpy(p1->data, coef2, 3*sizeof(int));
194
+ for (n = 2; n < n1; n++) {
195
+ gsl_vector_int_memcpy(p0, p1);
196
+ mygsl_vector_int_shift(p0, n);
197
+ for (j = 0; j < n; j++) {
198
+ gsl_vector_int_set(p1, j, gsl_vector_int_get(p1, j+1)*(j+1));
199
+ }
200
+ gsl_vector_int_set(p1, n, 0);
201
+ mygsl_vector_int_shift(p1, n);
202
+ gsl_vector_int_add(p0, p1);
203
+ /* save for the next iteration */
204
+ gsl_vector_int_memcpy(p1, p0);
205
+ }
206
+ gsl_vector_int_free(p1);
207
+ break;
208
+ }
209
+ return p0;
210
+ }
211
+
212
+ static VALUE rb_gsl_poly_define_poly(VALUE klass, VALUE order,
213
+ gsl_poly_int* (*f)(int n1)) {
214
+ int n1;
215
+ gsl_poly_int *pnew = NULL;
216
+ CHECK_FIXNUM(order);
217
+ n1 = FIX2INT(order);
218
+ if (n1 < 0) rb_raise(rb_eArgError, "order must be >= 0");
219
+ pnew = (*f)(n1);
220
+ return Data_Wrap_Struct(cgsl_poly_int, 0, gsl_vector_int_free, pnew);
221
+ }
222
+
223
+ static VALUE rb_gsl_poly_hermite(VALUE klass, VALUE order)
224
+ {
225
+ return rb_gsl_poly_define_poly(klass, order, mygsl_poly_hermite);
226
+ }
227
+
228
+ static VALUE rb_gsl_poly_cheb(VALUE klass, VALUE order)
229
+ {
230
+ return rb_gsl_poly_define_poly(klass, order, mygsl_poly_cheb);
231
+ }
232
+
233
+ static VALUE rb_gsl_poly_chebII(VALUE klass, VALUE order)
234
+ {
235
+ return rb_gsl_poly_define_poly(klass, order, mygsl_poly_chebII);
236
+ }
237
+
238
+ static VALUE rb_gsl_poly_laguerre(VALUE klass, VALUE order)
239
+ {
240
+ return rb_gsl_poly_define_poly(klass, order, mygsl_poly_laguerre);
241
+ }
242
+
243
+ static VALUE rb_gsl_poly_bessel(VALUE klass, VALUE order)
244
+ {
245
+ return rb_gsl_poly_define_poly(klass, order, mygsl_poly_bessel);
246
+ }
247
+
248
+ static VALUE rb_gsl_poly_bell(VALUE klass, VALUE order)
249
+ {
250
+ return rb_gsl_poly_define_poly(klass, order, mygsl_poly_bell);
251
+ }
252
+
253
+ void Init_gsl_poly2(VALUE module)
254
+ {
255
+ rb_define_singleton_method(cgsl_poly, "hermite", rb_gsl_poly_hermite, 1);
256
+ rb_define_singleton_method(cgsl_poly, "cheb", rb_gsl_poly_cheb, 1);
257
+ rb_define_singleton_method(cgsl_poly, "chebyshev", rb_gsl_poly_cheb, 1);
258
+ rb_define_singleton_method(cgsl_poly, "cheb_I", rb_gsl_poly_cheb, 1);
259
+ rb_define_singleton_method(cgsl_poly, "chebyshev_I", rb_gsl_poly_cheb, 1);
260
+ rb_define_singleton_method(cgsl_poly, "cheb_II", rb_gsl_poly_chebII, 1);
261
+ rb_define_singleton_method(cgsl_poly, "chebyshev_II", rb_gsl_poly_chebII, 1);
262
+ rb_define_singleton_method(cgsl_poly, "bessel", rb_gsl_poly_bessel, 1);
263
+ rb_define_singleton_method(cgsl_poly, "bell", rb_gsl_poly_bell, 1);
264
+ rb_define_singleton_method(cgsl_poly, "laguerre", rb_gsl_poly_laguerre, 1);
265
+ }
@@ -0,0 +1,1915 @@
1
+ /*
2
+ poly_source.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+
12
+ #ifdef BASE_DOUBLE
13
+ #define NUMCONV(x) NUM2DBL(x)
14
+ #define NUMCONV2(x) NUM2DBL(x)
15
+ #define MAT_ROW_COL MATRIX_ROW_COL
16
+ #define MAT_P MATRIX_P
17
+ #define MAT_ROW_P MATRIX_ROW_P
18
+ #define MAT_COL_P MATRIX_COL_P
19
+ #define C_TO_VALUE rb_float_new
20
+ #define C_TO_VALUE2 rb_float_new
21
+ #define CHECK_MAT CHECK_MATRIX
22
+ #define MAT_VIEW_P MATRIX_VIEW_P
23
+ #define PRINTF_FORMAT "%4.3e "
24
+ #define VEC_ROW_COL VECTOR_ROW_COL
25
+ #define VEC_P VECTOR_P
26
+ #define VEC_ROW_P VECTOR_ROW_P
27
+ #define VEC_COL_P VECTOR_COL_P
28
+ #define CHECK_VEC CHECK_VECTOR
29
+ #define VEC_VIEW_P VECTOR_VIEW_P
30
+ #elif defined(BASE_INT)
31
+ #define NUMCONV(x) NUM2DBL(x)
32
+ #define NUMCONV2(x) NUM2INT(x)
33
+ #define PRINTF_FORMAT "%d "
34
+ #define MAT_ROW_COL MATRIX_INT_ROW_COL
35
+ #define MAT_P MATRIX_INT_P
36
+ #define C_TO_VALUE INT2FIX
37
+ #define C_TO_VALUE2 INT2NUM
38
+ #define MAT_ROW_P MATRIX_INT_ROW_P
39
+ #define MAT_COL_P MATRIX_INT_COL_P
40
+ #define CHECK_MAT CHECK_MATRIX_INT
41
+ #define MAT_VIEW_P MATRIX_INT_VIEW_P
42
+ #define VEC_ROW_COL VECTOR_INT_ROW_COL
43
+ #define VEC_P VECTOR_INT_P
44
+ #define VEC_ROW_P VECTOR_INT_ROW_P
45
+ #define VEC_COL_P VECTOR_INT_COL_P
46
+ #define CHECK_VEC CHECK_VECTOR_INT
47
+ #define VEC_VIEW_P VECTOR_INT_VIEW_P
48
+ #endif
49
+
50
+ #ifdef BASE_DOUBLE
51
+ VALUE cgsl_poly, cgsl_poly_int;
52
+ VALUE cgsl_poly_workspace;
53
+ VALUE cgsl_poly_complex_workspace;
54
+ #ifdef GSL_1_1_LATER
55
+ VALUE cgsl_poly_dd;
56
+ VALUE cgsl_poly_taylor;
57
+ #endif
58
+ #endif
59
+
60
+ #ifdef BASE_INT
61
+ double gsl_poly_int_eval(const BASE c[], const int len, const double x)
62
+ {
63
+ int i;
64
+ double ans = (double) c[len-1];
65
+ for(i=len-1; i>0; i--) ans = (double) c[i-1] + x * ans;
66
+ return ans;
67
+ }
68
+ #endif
69
+ #ifdef BASE_DOUBLE
70
+ #ifdef HAVE_NARRAY_H
71
+ #include "rb_gsl_with_narray.h"
72
+ #endif
73
+ #ifdef GSL_1_11_LATER
74
+ static VALUE rb_gsl_complex_poly_complex_eval(VALUE a, VALUE b);
75
+ #endif
76
+ static VALUE rb_gsl_poly_eval_singleton(VALUE klass, VALUE a, VALUE x)
77
+ {
78
+ gsl_vector *v = NULL, *vx, *vnew;
79
+ gsl_matrix *mx, *mnew;
80
+ double rslt;
81
+ int flag = 0;
82
+ size_t i, N, n;
83
+ VALUE val;
84
+ double *ptr0;
85
+ double *ptr1, *ptr2;
86
+ #ifdef HAVE_NARRAY_H
87
+ int shape[1];
88
+ #endif
89
+ #ifdef GSL_1_11_LATER
90
+ gsl_complex *z, zz;
91
+ gsl_vector_complex *vz, *vznew;
92
+ if (rb_obj_is_kind_of(a, cgsl_vector_complex))
93
+ return rb_gsl_complex_poly_complex_eval(a, x);
94
+ #endif
95
+ switch (TYPE(a)) {
96
+ case T_ARRAY:
97
+ #ifdef GSL_1_11_LATER
98
+ if (rb_obj_is_kind_of(rb_ary_entry(a, 0), cgsl_complex))
99
+ return rb_gsl_complex_poly_complex_eval(a, x);
100
+ #endif
101
+ v = make_cvector_from_rarray(a);
102
+ N = v->size;
103
+ ptr0 = v->data;
104
+ flag = 1;
105
+ break;
106
+ default:
107
+ if (rb_obj_is_kind_of(a, cgsl_vector)) {
108
+ Data_Get_Struct(a, gsl_vector, v);
109
+ N = v->size;
110
+ ptr0 = v->data;
111
+ #ifdef HAVE_NARRAY_H
112
+ } else if (NA_IsNArray(a)) {
113
+ N = NA_TOTAL(a);
114
+ ptr0 = NA_PTR_TYPE(a, double*);
115
+ #endif
116
+ } else {
117
+ rb_raise(rb_eTypeError, "Wrong argument type %s (Array, GSL::Vector or NArray expected)",
118
+ rb_class2name(CLASS_OF(a)));
119
+ }
120
+ }
121
+ switch (TYPE(x)) {
122
+ case T_FIXNUM:
123
+ case T_BIGNUM:
124
+ case T_FLOAT:
125
+ val = rb_float_new(gsl_poly_eval(ptr0, N, NUM2DBL(x)));
126
+ break;
127
+ case T_ARRAY:
128
+ n = RARRAY_LEN(x);
129
+ val = rb_ary_new2(n);
130
+ for (i = 0; i < n; i++) {
131
+ rslt = gsl_poly_eval(ptr0, N, NUM2DBL(rb_ary_entry(x, i)));
132
+ rb_ary_store(val, i, rb_float_new(rslt));
133
+ }
134
+ break;
135
+ default:
136
+ if (rb_obj_is_kind_of(x, cgsl_vector)) {
137
+ Data_Get_Struct(x, gsl_vector, vx);
138
+ vnew = gsl_vector_alloc(vx->size);
139
+ val = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
140
+ n = vx->size;
141
+ ptr1 = vx->data;
142
+ ptr2 = vnew->data;
143
+ } else if (rb_obj_is_kind_of(x, cgsl_matrix)) {
144
+ Data_Get_Struct(x, gsl_matrix, mx);
145
+ mnew = gsl_matrix_alloc(mx->size1, mx->size2);
146
+ val = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
147
+ n = mx->size1*mx->size2;
148
+ ptr1 = mx->data;
149
+ ptr2 = mnew->data;
150
+ #ifdef HAVE_NARRAY_H
151
+ } else if (NA_IsNArray(x)) {
152
+ shape[0] = NA_TOTAL(x);
153
+ n = shape[0];
154
+ val = na_make_object(NA_DFLOAT, 1, shape, CLASS_OF(x));
155
+ ptr1 = NA_PTR_TYPE(x, double*);
156
+ ptr2 = NA_PTR_TYPE(val, double*);
157
+ #endif
158
+ #ifdef GSL_1_11_LATER
159
+ } else if (rb_obj_is_kind_of(x, cgsl_complex)) {
160
+ Data_Get_Struct(x, gsl_complex, z);
161
+ zz = gsl_poly_complex_eval(ptr0, N, *z);
162
+ z = make_complex(GSL_REAL(zz), GSL_IMAG(zz));
163
+ if (flag == 1) gsl_vector_free(v);
164
+ return Data_Wrap_Struct(cgsl_complex, 0, free, z);
165
+ } else if (rb_obj_is_kind_of(x, cgsl_vector_complex)) {
166
+ Data_Get_Struct(x, gsl_vector_complex, vz);
167
+ vznew = gsl_vector_complex_alloc(vz->size);
168
+ for (i = 0; i < vz->size; i++) {
169
+ zz = gsl_poly_complex_eval(ptr0, N, gsl_vector_complex_get(vz, i));
170
+ gsl_vector_complex_set(vznew, i, zz);
171
+ }
172
+ if (flag == 1) gsl_vector_free(v);
173
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vznew);
174
+ #endif
175
+ } else {
176
+ rb_raise(rb_eTypeError, "Wrong argument type %s (A number, Array, GSL::Vector or NArray expected)",
177
+ rb_class2name(CLASS_OF(a)));
178
+ }
179
+ for (i = 0; i < n; i++) {
180
+ ptr2[i] = gsl_poly_eval(ptr0, N, ptr1[i]);
181
+ }
182
+ }
183
+ if (flag == 1) gsl_vector_free(v);
184
+ return val;
185
+ }
186
+ #ifdef GSL_1_11_LATER
187
+ static VALUE rb_gsl_complex_poly_complex_eval(VALUE a, VALUE b)
188
+ {
189
+ gsl_vector_complex *coef, *zb, *vnew;
190
+ gsl_complex *zc;
191
+ gsl_complex z, *zx, *res;
192
+ VALUE ret;
193
+ size_t i, N;
194
+ int flag = 0;
195
+ if (rb_obj_is_kind_of(a, cgsl_vector_complex)) {
196
+ Data_Get_Struct(a, gsl_vector_complex, coef);
197
+ N = coef->size;
198
+ zc = (gsl_complex*) coef->data;
199
+ } else if (TYPE(a) == T_ARRAY) {
200
+ N = RARRAY_LEN(a);
201
+ zc = (gsl_complex*) malloc(sizeof(gsl_complex));
202
+ flag = 1;
203
+ for (i = 0; i < N; i++) {
204
+ Data_Get_Struct(rb_ary_entry(a, i), gsl_complex, zx);
205
+ zc[i] = *zx;
206
+ }
207
+ } else {
208
+ rb_raise(rb_eTypeError, "rb_gsl_complex_poly_complex_solve: wrong argument type %s (GSL::Vector::Complex or Array expected)\n", rb_class2name(CLASS_OF(a)));
209
+ }
210
+
211
+ switch (TYPE(b)) {
212
+ case T_FIXNUM:
213
+ case T_BIGNUM:
214
+ case T_FLOAT:
215
+ res = (gsl_complex*) malloc(sizeof(gsl_complex));
216
+ ret = Data_Wrap_Struct(cgsl_complex, 0, free, res);
217
+ GSL_SET_REAL(&z, NUM2DBL(b));
218
+ GSL_SET_IMAG(&z, 0.0);
219
+ *res = gsl_complex_poly_complex_eval(zc, coef->size, z);
220
+ break;
221
+ case T_ARRAY:
222
+ ret = rb_ary_new2(RARRAY_LEN(b));
223
+ for (i = 0; i < RARRAY_LEN(b); i++) {
224
+ Data_Get_Struct(rb_ary_entry(b, i), gsl_complex, zx);
225
+ res = (gsl_complex*) malloc(sizeof(gsl_complex));
226
+ *res = gsl_complex_poly_complex_eval(zc, N, *zx);
227
+ rb_ary_store(ret, i, Data_Wrap_Struct(cgsl_complex, 0, free, res));
228
+ }
229
+ break;
230
+ default:
231
+ if (rb_obj_is_kind_of(b, cgsl_complex)) {
232
+ res = (gsl_complex*) malloc(sizeof(gsl_complex));
233
+ ret = Data_Wrap_Struct(cgsl_complex, 0, free, res);
234
+ Data_Get_Struct(b, gsl_complex, zx);
235
+ *res = gsl_complex_poly_complex_eval(zc, N, *zx);
236
+ } else if (rb_obj_is_kind_of(b, cgsl_vector_complex)) {
237
+ Data_Get_Struct(b, gsl_vector_complex, zb);
238
+ vnew = gsl_vector_complex_alloc(zb->size);
239
+ ret = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
240
+ for (i = 0; i < zb->size; i++) {
241
+ z = gsl_vector_complex_get(zb, i);
242
+ gsl_vector_complex_set(vnew, i, gsl_complex_poly_complex_eval(zc, N, z));
243
+ }
244
+ } else {
245
+ rb_raise(rb_eTypeError, "Wrong argument type %s.\n", rb_class2name(CLASS_OF(b)));
246
+ }
247
+ }
248
+ if (flag == 1) free(zc);
249
+ return ret;
250
+ }
251
+ #endif
252
+ #endif
253
+
254
+ static VALUE FUNCTION(rb_gsl_poly,eval)(VALUE obj, VALUE xx)
255
+ {
256
+ GSL_TYPE(gsl_poly) *p = NULL;
257
+ GSL_TYPE(gsl_vector) *v = NULL;
258
+ GSL_TYPE(gsl_matrix) *m = NULL;
259
+ gsl_vector *vnew = NULL;
260
+ gsl_matrix *mnew = NULL;
261
+ VALUE x, ary;
262
+ size_t i, j;
263
+ #ifdef BASE_DOUBLE
264
+ #ifdef HAVE_NARRAY_H
265
+ struct NARRAY *na;
266
+ double *ptr1, *ptr2;
267
+ size_t n;
268
+ #endif
269
+ #ifdef GSL_1_11_LATER
270
+ gsl_complex *z, zz;
271
+ gsl_vector_complex *vz, *vznew;
272
+ #endif
273
+ #endif
274
+
275
+ Data_Get_Struct(obj, GSL_TYPE(gsl_poly), p);
276
+ if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
277
+ switch (TYPE(xx)) {
278
+ case T_FIXNUM:
279
+ case T_BIGNUM:
280
+ case T_FLOAT:
281
+ return rb_float_new(FUNCTION(gsl_poly,eval)(p->data, p->size, NUM2DBL(xx)));
282
+ break;
283
+ case T_ARRAY:
284
+ ary = rb_ary_new2(RARRAY_LEN(xx));
285
+ for (i = 0; i < RARRAY_LEN(xx); i++) {
286
+ x = rb_ary_entry(xx, i);
287
+ Need_Float(x);
288
+ rb_ary_store(ary, i, rb_float_new(FUNCTION(gsl_poly,eval)(p->data, p->size, NUM2DBL(x))));
289
+ }
290
+ return ary;
291
+ break;
292
+ default:
293
+ #ifdef BASE_DOUBLE
294
+ #ifdef HAVE_NARRAY_H
295
+ if (NA_IsNArray(xx)) {
296
+ GetNArray(xx, na);
297
+ ptr1 = (double*) na->ptr;
298
+ n = na->total;
299
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
300
+ ptr2 = NA_PTR_TYPE(ary,double*);
301
+ for (i = 0; i < n; i++) ptr2[i] = FUNCTION(gsl_poly,eval)(p->data,p->size,ptr1[i]);
302
+ return ary;
303
+ }
304
+ #endif
305
+ #endif
306
+ if (VEC_P(xx)) {
307
+ Data_Get_Struct(xx, GSL_TYPE(gsl_vector), v);
308
+ vnew = gsl_vector_alloc(v->size);
309
+ for (i = 0; i < v->size; i++) {
310
+ gsl_vector_set(vnew, i, FUNCTION(gsl_poly,eval)(p->data, p->size, FUNCTION(gsl_vector,get)(v, i)));
311
+ }
312
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
313
+ } else if (MAT_P(xx)) {
314
+ Data_Get_Struct(xx, GSL_TYPE(gsl_matrix), m);
315
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
316
+ for (i = 0; i < m->size1; i++) {
317
+ for (j = 0; j < m->size2; j++) {
318
+ gsl_matrix_set(mnew, i, j,
319
+ FUNCTION(gsl_poly,eval)(p->data, p->size, FUNCTION(gsl_matrix,get)(m, i, j)));
320
+ }
321
+ }
322
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
323
+ #ifdef BASE_DOUBLE
324
+ #ifdef GSL_1_11_LATER
325
+ } else if (rb_obj_is_kind_of(xx, cgsl_complex)) {
326
+ Data_Get_Struct(xx, gsl_complex, z);
327
+ zz = gsl_poly_complex_eval(p->data, p->size, *z);
328
+ z = make_complex(GSL_REAL(zz), GSL_IMAG(zz));
329
+ return Data_Wrap_Struct(cgsl_complex, 0, free, z);
330
+ } else if (rb_obj_is_kind_of(xx, cgsl_vector_complex)) {
331
+ Data_Get_Struct(xx, gsl_vector_complex, vz);
332
+ vznew = gsl_vector_complex_alloc(vz->size);
333
+ for (i = 0; i < vz->size; i++) {
334
+ zz = gsl_poly_complex_eval(p->data, p->size, gsl_vector_complex_get(vz, i));
335
+ gsl_vector_complex_set(vznew, i, zz);
336
+ }
337
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vznew);
338
+ #endif
339
+ #endif
340
+ } else {
341
+ rb_raise(rb_eTypeError, "wrong argument type");
342
+ }
343
+ break;
344
+ }
345
+ return Qnil; /* never reach here */
346
+ }
347
+
348
+ /* singleton method */
349
+ static VALUE FUNCTION(rb_gsl_poly,eval2)(int argc, VALUE *argv, VALUE obj)
350
+ {
351
+ GSL_TYPE(gsl_poly) *p = NULL;
352
+ GSL_TYPE(gsl_vector) *v = NULL;
353
+ GSL_TYPE(gsl_matrix) *m = NULL;
354
+ gsl_vector *vnew = NULL;
355
+ gsl_matrix *mnew = NULL;
356
+ VALUE xx, x, ary;
357
+ size_t i, j, size;
358
+ #ifdef BASE_DOUBLE
359
+ #ifdef HAVE_NARRAY_H
360
+ struct NARRAY *na;
361
+ double *ptr1, *ptr2;
362
+ #endif
363
+ #endif
364
+ switch (argc) {
365
+ case 2:
366
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_poly), p);
367
+ size = p->size;
368
+ xx = argv[1];
369
+ break;
370
+ case 3:
371
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_poly), p);
372
+ size = FIX2INT(argv[1]);
373
+ xx = argv[2];
374
+ break;
375
+ default:
376
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
377
+ break;
378
+ }
379
+ if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
380
+ switch (TYPE(xx)) {
381
+ case T_FIXNUM:
382
+ case T_BIGNUM:
383
+ case T_FLOAT:
384
+ return rb_float_new(FUNCTION(gsl_poly,eval)(p->data, size, NUM2DBL(xx)));
385
+ break;
386
+ case T_ARRAY:
387
+ ary = rb_ary_new2(RARRAY_LEN(xx));
388
+ for (i = 0; i < RARRAY_LEN(xx); i++) {
389
+ x = rb_ary_entry(xx, i);
390
+ Need_Float(x);
391
+ rb_ary_store(ary, i, rb_float_new(FUNCTION(gsl_poly,eval)(p->data, size, NUM2DBL(x))));
392
+ }
393
+ return ary;
394
+ break;
395
+ default:
396
+ #ifdef BASE_DOUBLE
397
+ #ifdef HAVE_NARRAY_H
398
+ if (NA_IsNArray(xx)) {
399
+ GetNArray(xx, na);
400
+ ptr1 = (double*) na->ptr;
401
+ size = na->total;
402
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
403
+ ptr2 = NA_PTR_TYPE(ary,double*);
404
+ for (i = 0; i < size; i++) ptr2[i] = FUNCTION(gsl_poly,eval)(p->data,p->size,ptr1[i]);
405
+ return ary;
406
+ }
407
+ #endif
408
+ #endif
409
+ if (VEC_P(xx)) {
410
+ Data_Get_Struct(xx, GSL_TYPE(gsl_vector), v);
411
+ vnew = gsl_vector_alloc(v->size);
412
+ for (i = 0; i < v->size; i++) {
413
+ gsl_vector_set(vnew, i, FUNCTION(gsl_poly,eval)(p->data, size, FUNCTION(gsl_vector,get)(v, i)));
414
+ }
415
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
416
+ } else if (MAT_P(xx)) {
417
+ Data_Get_Struct(xx, GSL_TYPE(gsl_matrix), m);
418
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
419
+ for (i = 0; i < m->size1; i++) {
420
+ for (j = 0; j < m->size2; j++) {
421
+ gsl_matrix_set(mnew, i, j,
422
+ FUNCTION(gsl_poly,eval)(p->data, size, FUNCTION(gsl_matrix,get)(m, i, j)));
423
+ }
424
+ }
425
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
426
+ } else {
427
+ rb_raise(rb_eTypeError, "wrong argument type");
428
+ }
429
+ break;
430
+ }
431
+ return Qnil; /* never reach here */
432
+ }
433
+
434
+ /* ax*x + bx + c = 0 */
435
+ static VALUE FUNCTION(rb_gsl_poly,solve_quadratic)(int argc, VALUE *argv, VALUE obj)
436
+ {
437
+ double x0, x1;
438
+ GSL_TYPE(gsl_poly) *v = NULL;
439
+ gsl_vector *r;
440
+ int n;
441
+ switch (argc) {
442
+ case 3:
443
+ n = gsl_poly_solve_quadratic(NUMCONV2(argv[0]), NUMCONV2(argv[1]), NUMCONV2(argv[2]),
444
+ &x0, &x1);
445
+ break;
446
+ case 1:
447
+ switch (TYPE(argv[0])) {
448
+ case T_ARRAY:
449
+ n = gsl_poly_solve_quadratic(NUMCONV2(rb_ary_entry(argv[0], 0)),
450
+ NUMCONV2(rb_ary_entry(argv[0], 1)),
451
+ NUMCONV2(rb_ary_entry(argv[0], 2)),
452
+ &x0, &x1);
453
+ break;
454
+ default:
455
+ CHECK_VEC(argv[0]);
456
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_poly), v);
457
+ n = gsl_poly_solve_quadratic(FUNCTION(gsl_vector,get)(v, 0),
458
+ FUNCTION(gsl_vector,get)(v, 1),
459
+ FUNCTION(gsl_vector,get)(v, 2),
460
+ &x0, &x1);
461
+ break;
462
+ }
463
+ break;
464
+ default:
465
+ rb_raise(rb_eArgError,
466
+ "wrong number of arguments (3 numbers or 1 array or 1 vector)");
467
+ break;
468
+ }
469
+ // If n == 0, we want to return an empty gsl_vector, but gsl_vectors can'y be
470
+ // empty, so just return an empty Array.
471
+ if(n == 0) {
472
+ return rb_ary_new();
473
+ }
474
+ r = gsl_vector_alloc(n);
475
+ switch(n) {
476
+ case 2: gsl_vector_set(r, 1, x1); /* fall through */
477
+ case 1: gsl_vector_set(r, 0, x0);
478
+ }
479
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
480
+ }
481
+
482
+ static VALUE FUNCTION(rb_gsl_poly,complex_solve_quadratic)(int argc, VALUE *argv, VALUE obj)
483
+ {
484
+ gsl_complex z0, z1;
485
+ GSL_TYPE(gsl_vector) *v = NULL;
486
+ gsl_vector_complex *r = NULL;
487
+ int n;
488
+ switch (argc) {
489
+ case 3:
490
+ n = gsl_poly_complex_solve_quadratic(NUMCONV2(argv[0]),
491
+ NUMCONV2(argv[1]), NUMCONV2(argv[2]),
492
+ &z0, &z1);
493
+ break;
494
+ case 1:
495
+ switch (TYPE(argv[0])) {
496
+ case T_ARRAY:
497
+ n = gsl_poly_complex_solve_quadratic(NUMCONV2(rb_ary_entry(argv[0], 0)),
498
+ NUMCONV2(rb_ary_entry(argv[0], 1)),
499
+ NUMCONV2(rb_ary_entry(argv[0], 2)),
500
+ &z0, &z1);
501
+ break;
502
+ default:
503
+ CHECK_VEC(argv[0]);
504
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
505
+ n = gsl_poly_complex_solve_quadratic(FUNCTION(gsl_vector,get)(v, 0),
506
+ FUNCTION(gsl_vector,get)(v, 1),
507
+ FUNCTION(gsl_vector,get)(v, 2),
508
+ &z0, &z1);
509
+ break;
510
+ }
511
+ break;
512
+ default:
513
+ rb_raise(rb_eArgError,
514
+ "wrong number of arguments (3 numbers or 1 array or 1 vector)");
515
+ break;
516
+ }
517
+ // If n == 0, we want to return an empty gsl_vector, but gsl_vectors can'y be
518
+ // empty, so just return an empty Array.
519
+ if(n == 0) {
520
+ return rb_ary_new();
521
+ }
522
+ r = gsl_vector_complex_alloc(n);
523
+ switch(n) {
524
+ case 2: gsl_vector_complex_set(r, 1, z1); /* fall through */
525
+ case 1: gsl_vector_complex_set(r, 0, z0);
526
+ }
527
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
528
+ }
529
+
530
+ static VALUE FUNCTION(rb_gsl_poly,solve_cubic)(int argc, VALUE *argv, VALUE obj)
531
+ {
532
+ double x0, x1, x2;
533
+ GSL_TYPE(gsl_vector) *v = NULL;
534
+ gsl_vector *r = NULL;
535
+ int n;
536
+ switch (argc) {
537
+ case 3:
538
+ n = gsl_poly_solve_cubic(NUMCONV2(argv[0]), NUMCONV2(argv[1]), NUMCONV2(argv[2]),
539
+ &x0, &x1, &x2);
540
+ break;
541
+ case 1:
542
+ switch (TYPE(argv[0])) {
543
+ case T_ARRAY:
544
+ n = gsl_poly_solve_cubic(NUMCONV2(rb_ary_entry(argv[0], 0)),
545
+ NUMCONV2(rb_ary_entry(argv[0], 1)),
546
+ NUMCONV2(rb_ary_entry(argv[0], 2)),
547
+ &x0, &x1, &x2);
548
+ break;
549
+ default:
550
+ CHECK_VEC(argv[0]);
551
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
552
+ n = gsl_poly_solve_cubic(FUNCTION(gsl_vector,get)(v, 0),
553
+ FUNCTION(gsl_vector,get)(v, 1),
554
+ FUNCTION(gsl_vector,get)(v, 2),
555
+ &x0, &x1, &x2);
556
+ break;
557
+ }
558
+ break;
559
+ default:
560
+ rb_raise(rb_eArgError,
561
+ "wrong number of arguments (3 numbers or 1 array or 1 vector)");
562
+ break;
563
+ }
564
+ r = gsl_vector_alloc(n);
565
+ switch(n) {
566
+ case 3: gsl_vector_set(r, 2, x2); /* fall through */
567
+ case 2: gsl_vector_set(r, 1, x1); /* fall through */
568
+ case 1: gsl_vector_set(r, 0, x0);
569
+ }
570
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
571
+ }
572
+
573
+ static VALUE FUNCTION(rb_gsl_poly,complex_solve_cubic)(int argc, VALUE *argv, VALUE obj)
574
+ {
575
+ gsl_complex z0, z1, z2;
576
+ GSL_TYPE(gsl_vector) *v = NULL;
577
+ gsl_vector_complex *r = NULL;
578
+ int n;
579
+ switch (argc) {
580
+ case 3:
581
+ n = gsl_poly_complex_solve_cubic(NUMCONV2(argv[0]), NUMCONV2(argv[1]), NUMCONV2(argv[2]),
582
+ &z0, &z1, &z2);
583
+ break;
584
+ case 1:
585
+ switch (TYPE(argv[0])) {
586
+ case T_ARRAY:
587
+ n = gsl_poly_complex_solve_cubic(NUMCONV2(rb_ary_entry(argv[0], 0)),
588
+ NUMCONV2(rb_ary_entry(argv[0], 1)),
589
+ NUMCONV2(rb_ary_entry(argv[0], 2)),
590
+ &z0, &z1, &z2);
591
+ break;
592
+ default:
593
+ CHECK_VEC(argv[0]);
594
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
595
+ n = gsl_poly_complex_solve_cubic(FUNCTION(gsl_vector,get)(v, 0),
596
+ FUNCTION(gsl_vector,get)(v, 1),
597
+ FUNCTION(gsl_vector,get)(v, 2),
598
+ &z0, &z1, &z2);
599
+ break;
600
+ }
601
+ break;
602
+ default:
603
+ rb_raise(rb_eArgError,
604
+ "wrong number of arguments (3 numbers or 1 array or 1 vector)");
605
+ break;
606
+ }
607
+ r = gsl_vector_complex_alloc(n);
608
+ switch(n) {
609
+ case 3: gsl_vector_complex_set(r, 2, z2); /* fall through */
610
+ case 2: gsl_vector_complex_set(r, 1, z1); /* fall through */
611
+ case 1: gsl_vector_complex_set(r, 0, z0);
612
+ }
613
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
614
+ }
615
+
616
+ #ifdef HAVE_POLY_SOLVE_QUARTIC
617
+ static VALUE FUNCTION(rb_gsl_poly,solve_quartic)(int argc, VALUE *argv, VALUE obj)
618
+ {
619
+ double x0, x1, x2, x3;
620
+ GSL_TYPE(gsl_vector) *v = NULL;
621
+ gsl_vector *r = NULL;
622
+ int n;
623
+ switch (argc) {
624
+ case 4:
625
+ n = gsl_poly_solve_quartic(NUMCONV2(argv[0]), NUMCONV2(argv[1]), NUMCONV2(argv[2]),
626
+ NUMCONV2(argv[3]),
627
+ &x0, &x1, &x2, &x3);
628
+ break;
629
+ case 1:
630
+ switch (TYPE(argv[0])) {
631
+ case T_ARRAY:
632
+ n = gsl_poly_solve_quartic(NUMCONV2(rb_ary_entry(argv[0], 0)),
633
+ NUMCONV2(rb_ary_entry(argv[0], 1)),
634
+ NUMCONV2(rb_ary_entry(argv[0], 2)),
635
+ NUMCONV2(rb_ary_entry(argv[0], 3)),
636
+ &x0, &x1, &x2, &x3);
637
+ break;
638
+ default:
639
+ CHECK_VEC(argv[0]);
640
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
641
+ n = gsl_poly_solve_quartic(FUNCTION(gsl_vector,get)(v, 0),
642
+ FUNCTION(gsl_vector,get)(v, 1),
643
+ FUNCTION(gsl_vector,get)(v, 2),
644
+ FUNCTION(gsl_vector,get)(v, 3),
645
+ &x0, &x1, &x2, &x3);
646
+ break;
647
+ }
648
+ break;
649
+ default:
650
+ rb_raise(rb_eArgError,
651
+ "wrong number of arguments (3 numbers or 1 array or 1 vector)");
652
+ break;
653
+ }
654
+ r = gsl_vector_alloc(n);
655
+ switch(n) {
656
+ case 4: gsl_vector_set(r, 3, x3); /* fall through */
657
+ case 3: gsl_vector_set(r, 2, x2); /* fall through */
658
+ case 2: gsl_vector_set(r, 1, x1); /* fall through */
659
+ case 1: gsl_vector_set(r, 0, x0);
660
+ }
661
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
662
+ }
663
+
664
+ static VALUE FUNCTION(rb_gsl_poly,complex_solve_quartic)(int argc, VALUE *argv, VALUE obj)
665
+ {
666
+ gsl_complex z0, z1, z2, z3;
667
+ GSL_TYPE(gsl_vector) *v = NULL;
668
+ gsl_vector_complex *r = NULL;
669
+ int n;
670
+ switch (argc) {
671
+ case 4:
672
+ n = gsl_poly_complex_solve_quartic(NUMCONV2(argv[0]), NUMCONV2(argv[1]),
673
+ NUMCONV2(argv[2]), NUMCONV2(argv[3]),
674
+ &z0, &z1, &z2, &z3);
675
+ break;
676
+ case 1:
677
+ switch (TYPE(argv[0])) {
678
+ case T_ARRAY:
679
+ n = gsl_poly_complex_solve_quartic(NUMCONV2(rb_ary_entry(argv[0], 0)),
680
+ NUMCONV2(rb_ary_entry(argv[0], 1)),
681
+ NUMCONV2(rb_ary_entry(argv[0], 2)),
682
+ NUMCONV2(rb_ary_entry(argv[0], 3)),
683
+ &z0, &z1, &z2, &z3);
684
+ break;
685
+ default:
686
+ CHECK_VEC(argv[0]);
687
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
688
+ n = gsl_poly_complex_solve_quartic(FUNCTION(gsl_vector,get)(v, 0),
689
+ FUNCTION(gsl_vector,get)(v, 1),
690
+ FUNCTION(gsl_vector,get)(v, 2),
691
+ FUNCTION(gsl_vector,get)(v, 3),
692
+ &z0, &z1, &z2, &z3);
693
+ break;
694
+ }
695
+ break;
696
+ default:
697
+ rb_raise(rb_eArgError,
698
+ "wrong number of arguments (3 numbers or 1 array or 1 vector)");
699
+ break;
700
+ }
701
+ r = gsl_vector_complex_alloc(n);
702
+ switch(n) {
703
+ case 4: gsl_vector_complex_set(r, 0, z0); /* fall through */
704
+ case 3: gsl_vector_complex_set(r, 1, z1); /* fall through */
705
+ case 2: gsl_vector_complex_set(r, 2, z2); /* fall through */
706
+ case 1: gsl_vector_complex_set(r, 3, z3);
707
+ }
708
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
709
+ }
710
+
711
+ #endif
712
+ /* singleton method */
713
+ VALUE FUNCTION(rb_gsl_poly,complex_solve)(int argc, VALUE *argv, VALUE obj)
714
+ {
715
+ int size = -1, size2;
716
+ gsl_poly_complex_workspace *w = NULL;
717
+ GSL_TYPE(gsl_vector) *v = NULL;
718
+ gsl_vector *a = NULL, *z = NULL;
719
+ gsl_complex c;
720
+ gsl_vector_complex *r = NULL;
721
+ int i, flag = 0;
722
+ // local variable "status" declared and set, but never used
723
+ //int status;
724
+
725
+ switch (argc) {
726
+ case 1:
727
+ break;
728
+ case 2:
729
+ if (TYPE(argv[1]) == T_FIXNUM) size = FIX2INT(argv[1]);
730
+ break;
731
+ case 3:
732
+ if (TYPE(argv[1]) == T_FIXNUM) size = FIX2INT(argv[1]);
733
+ break;
734
+ default:
735
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-3)", argc);
736
+ break;
737
+ }
738
+
739
+ switch (TYPE(argv[0])) {
740
+ case T_ARRAY:
741
+ if (size < 0) size = RARRAY_LEN(argv[0]);
742
+ a = gsl_vector_alloc(size);
743
+ for (i = 0; i < size; i++) gsl_vector_set(a, i, NUMCONV2(rb_ary_entry(argv[0], i)));
744
+ break;
745
+ case T_FIXNUM:
746
+ case T_BIGNUM:
747
+ case T_FLOAT:
748
+ if (rb_obj_is_kind_of(argv[argc-1], cgsl_poly_workspace)) size = argc - 1;
749
+ else size = argc;
750
+ a = gsl_vector_alloc(size);
751
+ for (i = 0; i < size; i++) gsl_vector_set(a, i, NUMCONV2(argv[i]));
752
+ break;
753
+ default:
754
+ if (rb_obj_is_kind_of(argv[0], GSL_TYPE(cgsl_vector))) {
755
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
756
+ if (size < 0) size = v->size;
757
+ } else {
758
+ rb_raise(rb_eTypeError, "wrong argument type (Array, Vector, or Numeric expected");
759
+ }
760
+ a = gsl_vector_alloc(v->size);
761
+ for (i = 0; i < size; i++) gsl_vector_set(a, i, FUNCTION(gsl_vector,get)(v, i));
762
+ break;
763
+ }
764
+ size2 = 2*(size - 1);
765
+ z = gsl_vector_alloc(size2);
766
+ if (rb_obj_is_kind_of(argv[argc-1], cgsl_poly_workspace)
767
+ || rb_obj_is_kind_of(argv[argc-1], cgsl_poly_complex_workspace)) {
768
+ Data_Get_Struct(argv[argc-1], gsl_poly_complex_workspace, w);
769
+ flag = 0;
770
+ } else {
771
+ w = gsl_poly_complex_workspace_alloc(size);
772
+ flag = 1;
773
+ }
774
+ /*status =*/ gsl_poly_complex_solve(a->data, size, w, z->data);
775
+
776
+ if (flag == 1) gsl_poly_complex_workspace_free(w);
777
+ gsl_vector_free(a);
778
+ r = gsl_vector_complex_alloc(size - 1);
779
+ for (i = 0; i < size - 1; i++) {
780
+ c.dat[0] = gsl_vector_get(z, i*2);
781
+ c.dat[1] = gsl_vector_get(z, i*2+1);
782
+ gsl_vector_complex_set(r, i, c);
783
+ }
784
+ gsl_vector_free(z);
785
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
786
+ }
787
+
788
+
789
+ /* a2 x*x + a1 x + a0 = 0 */
790
+ static VALUE FUNCTION(rb_gsl_poly,solve_quadratic2)(VALUE obj)
791
+ {
792
+ GSL_TYPE(gsl_vector) *v = NULL;
793
+ gsl_vector *r = NULL;
794
+ gsl_vector_complex *r2 = NULL;
795
+ double a2, a1, a0;
796
+ double d; /* determinant */
797
+ double x0, x1;
798
+ int n;
799
+ gsl_complex z0, z1;
800
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
801
+ if (v->size < 3) {
802
+ rb_raise(rb_eArgError, "the order of the object is less than 3.");
803
+ }
804
+ a2 = FUNCTION(gsl_vector,get)(v, 2); /* coefficients */
805
+ a1 = FUNCTION(gsl_vector,get)(v, 1);
806
+ a0 = FUNCTION(gsl_vector,get)(v, 0);
807
+ d = a1*a1 - 4.0*a2*a0; /* determinant */
808
+ if (d >= 0.0) {
809
+ n = gsl_poly_solve_quadratic(a2, a1, a0, &x0, &x1);
810
+ r = gsl_vector_alloc(n);
811
+ switch(n) {
812
+ case 2: gsl_vector_set(r, 1, x1); /* fall through */
813
+ case 1: gsl_vector_set(r, 0, x0);
814
+ }
815
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
816
+ } else {
817
+ n = gsl_poly_complex_solve_quadratic(a2, a1, a0, &z0, &z1);
818
+ r2 = gsl_vector_complex_alloc(n);
819
+ switch(n) {
820
+ case 2: gsl_vector_complex_set(r2, 1, z1); /* fall through */
821
+ case 1: gsl_vector_complex_set(r2, 0, z0);
822
+ }
823
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r2);
824
+ }
825
+
826
+ }
827
+
828
+
829
+ static VALUE FUNCTION(rb_gsl_poly,complex_solve_quadratic2)(VALUE obj)
830
+ {
831
+ GSL_TYPE(gsl_vector) *v = NULL;
832
+ gsl_vector_complex *r = NULL;
833
+ double a2, a1, a0;
834
+ int n;
835
+ gsl_complex z0, z1;
836
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
837
+ if (v->size < 3) {
838
+ rb_raise(rb_eArgError, "the order of the object is less than 3.");
839
+ }
840
+ a2 = FUNCTION(gsl_vector,get)(v, 2); /* coefficients */
841
+ a1 = FUNCTION(gsl_vector,get)(v, 1);
842
+ a0 = FUNCTION(gsl_vector,get)(v, 0);
843
+ n = gsl_poly_complex_solve_quadratic(a2, a1, a0, &z0, &z1);
844
+ r = gsl_vector_complex_alloc(n);
845
+ switch(n) {
846
+ case 2: gsl_vector_complex_set(r, 1, z1); /* fall through */
847
+ case 1: gsl_vector_complex_set(r, 0, z0);
848
+ }
849
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
850
+ }
851
+
852
+ /* x**3 + a2 x**2 + a1 x + a0 = 0 */
853
+ static VALUE FUNCTION(rb_gsl_poly,solve_cubic2)(VALUE obj)
854
+ {
855
+ GSL_TYPE(gsl_vector) *v = NULL;
856
+ gsl_vector *r = NULL;
857
+ double a3, a2, a1, a0;
858
+ double x0, x1, x2;
859
+ int n;
860
+
861
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
862
+ if (v->size < 4) {
863
+ rb_raise(rb_eArgError, "the order of the object is less than 4.");
864
+ }
865
+ a3 = FUNCTION(gsl_vector,get)(v, 3);
866
+ a2 = FUNCTION(gsl_vector,get)(v, 2)/a3; /* coefficients */
867
+ a1 = FUNCTION(gsl_vector,get)(v, 1)/a3;
868
+ a0 = FUNCTION(gsl_vector,get)(v, 0)/a3;
869
+ n = gsl_poly_solve_cubic(a2, a1, a0, &x0, &x1, &x2);
870
+ r = gsl_vector_alloc(n);
871
+ switch(n) {
872
+ case 3: gsl_vector_set(r, 2, x2); /* fall through */
873
+ case 2: gsl_vector_set(r, 1, x1); /* fall through */
874
+ case 1: gsl_vector_set(r, 0, x0);
875
+ }
876
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
877
+ }
878
+
879
+ static VALUE FUNCTION(rb_gsl_poly,complex_solve_cubic2)(VALUE obj)
880
+ {
881
+ GSL_TYPE(gsl_vector) *v = NULL;
882
+ gsl_vector_complex *r = NULL;
883
+ double a3, a2, a1, a0;
884
+ int n;
885
+ gsl_complex z0, z1, z2;
886
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
887
+ if (v->size < 4) {
888
+ rb_raise(rb_eArgError, "the order of the object is less than 4.");
889
+ }
890
+ a3 = FUNCTION(gsl_vector,get)(v, 3);
891
+ a2 = FUNCTION(gsl_vector,get)(v, 2)/a3; /* coefficients */
892
+ a1 = FUNCTION(gsl_vector,get)(v, 1)/a3;
893
+ a0 = FUNCTION(gsl_vector,get)(v, 0)/a3;
894
+ n = gsl_poly_complex_solve_cubic(a2, a1, a0, &z0, &z1, &z2);
895
+ r = gsl_vector_complex_alloc(n);
896
+ switch(n) {
897
+ case 3: gsl_vector_complex_set(r, 2, z2); /* fall through */
898
+ case 2: gsl_vector_complex_set(r, 1, z1); /* fall through */
899
+ case 1: gsl_vector_complex_set(r, 0, z0);
900
+ }
901
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
902
+ }
903
+
904
+ #ifdef HAVE_POLY_SOLVE_QUARTIC
905
+ /* a4 x**4 + a3 x**3 + a2 x**2 + a1 x + a0 = 0 */
906
+ static VALUE FUNCTION(rb_gsl_poly,solve_quartic2)(VALUE obj)
907
+ {
908
+ GSL_TYPE(gsl_vector) *v = NULL;
909
+ gsl_vector *r = NULL;
910
+ double a4, a3, a2, a1, a0;
911
+ double x0, x1, x2, x3;
912
+ int n;
913
+
914
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
915
+ if (v->size < 5) {
916
+ rb_raise(rb_eArgError, "the order of the object is less than 4.");
917
+ }
918
+ a4 = FUNCTION(gsl_vector,get)(v, 4);
919
+ a3 = FUNCTION(gsl_vector,get)(v, 3)/a4;
920
+ a2 = FUNCTION(gsl_vector,get)(v, 2)/a4; /* coefficients */
921
+ a1 = FUNCTION(gsl_vector,get)(v, 1)/a4;
922
+ a0 = FUNCTION(gsl_vector,get)(v, 0)/a4;
923
+ n = gsl_poly_solve_quartic(a3, a2, a1, a0, &x0, &x1, &x2, &x3);
924
+ r = gsl_vector_alloc(3);
925
+ r = gsl_vector_alloc(4);
926
+ gsl_vector_set(r, 0, x0);
927
+ gsl_vector_set(r, 1, x1);
928
+ gsl_vector_set(r, 2, x2);
929
+ gsl_vector_set(r, 3, x3);
930
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
931
+ }
932
+
933
+ static VALUE FUNCTION(rb_gsl_poly,complex_solve_quartic2)(VALUE obj)
934
+ {
935
+ GSL_TYPE(gsl_vector) *v = NULL;
936
+ gsl_vector_complex *r = NULL;
937
+ double a4, a3, a2, a1, a0;
938
+ int n;
939
+ gsl_complex z0, z1, z2, z3;
940
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
941
+ if (v->size < 5) {
942
+ rb_raise(rb_eArgError, "the order of the object is less than 4.");
943
+ }
944
+ a4 = FUNCTION(gsl_vector,get)(v, 4);
945
+ a3 = FUNCTION(gsl_vector,get)(v, 3)/a4;
946
+ a2 = FUNCTION(gsl_vector,get)(v, 2)/a4; /* coefficients */
947
+ a1 = FUNCTION(gsl_vector,get)(v, 1)/a4;
948
+ a0 = FUNCTION(gsl_vector,get)(v, 0)/a4;
949
+ n = gsl_poly_complex_solve_quartic(a3, a2, a1, a0, &z0, &z1, &z2, &z3);
950
+ r = gsl_vector_complex_alloc(4);
951
+ gsl_vector_complex_set(r, 0, z0);
952
+ gsl_vector_complex_set(r, 1, z1);
953
+ gsl_vector_complex_set(r, 2, z2);
954
+ gsl_vector_complex_set(r, 3, z3);
955
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
956
+ }
957
+
958
+ #endif
959
+
960
+ /* method */
961
+ VALUE FUNCTION(rb_gsl_poly,complex_solve2)(int argc, VALUE *argv, VALUE obj)
962
+ {
963
+ GSL_TYPE(gsl_vector) *v = NULL;
964
+ gsl_vector *a = NULL, *z = NULL;
965
+ size_t size, size2, i;
966
+ gsl_poly_complex_workspace *w = NULL;
967
+ gsl_complex c;
968
+ gsl_vector_complex *r = NULL;
969
+ int flag = 0;
970
+ // local variable "status" declared and set, but never used
971
+ //int status;
972
+
973
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
974
+ size = v->size;
975
+ size2 = 2*(size - 1);
976
+ z = gsl_vector_alloc(size2);
977
+ a = gsl_vector_alloc(v->size);
978
+ for (i = 0; i < v->size; i++) {
979
+ gsl_vector_set(a, i, FUNCTION(gsl_vector,get)(v, i));
980
+ }
981
+
982
+ if (argc == 1 && rb_obj_is_kind_of(argv[0], cgsl_poly_workspace)) {
983
+ Data_Get_Struct(argv[0], gsl_poly_complex_workspace, w);
984
+ flag = 0;
985
+ } else {
986
+ w = gsl_poly_complex_workspace_alloc(size);
987
+ flag = 1;
988
+ }
989
+
990
+ /*status =*/ gsl_poly_complex_solve(a->data, size, w, z->data);
991
+
992
+ r = gsl_vector_complex_alloc(size - 1);
993
+ for (i = 0; i < size - 1; i++) {
994
+ c.dat[0] = gsl_vector_get(z, i*2);
995
+ c.dat[1] = gsl_vector_get(z, i*2+1);
996
+ gsl_vector_complex_set(r, i, c);
997
+ }
998
+ gsl_vector_free(a);
999
+ gsl_vector_free(z);
1000
+ if (flag == 1) gsl_poly_complex_workspace_free(w);
1001
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
1002
+ }
1003
+
1004
+ #ifdef BASE_INT
1005
+ static VALUE rb_gsl_poly_int_to_f(VALUE obj)
1006
+ {
1007
+ gsl_vector *v;
1008
+ gsl_vector_int *vi;
1009
+ size_t i;
1010
+ Data_Get_Struct(obj, gsl_vector_int, vi);
1011
+ v = gsl_vector_alloc(vi->size);
1012
+ for (i = 0; i < v->size; i++)
1013
+ gsl_vector_set(v, i, (double) gsl_vector_int_get(vi, i));
1014
+ return Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, v);
1015
+ }
1016
+ #endif
1017
+
1018
+ #ifdef BASE_DOUBLE
1019
+ static VALUE rb_gsl_poly_to_i(VALUE obj)
1020
+ {
1021
+ gsl_vector *v;
1022
+ gsl_vector_int *vi;
1023
+ size_t i;
1024
+ Data_Get_Struct(obj, gsl_vector, v);
1025
+ vi = gsl_vector_int_alloc(v->size);
1026
+ for (i = 0; i < v->size; i++)
1027
+ gsl_vector_int_set(vi, i, (int) gsl_vector_get(v, i));
1028
+ return Data_Wrap_Struct(cgsl_poly_int, 0, gsl_vector_int_free, vi);
1029
+ }
1030
+
1031
+ static VALUE FUNCTION(rb_gsl_poly,workspace_new)(VALUE klass, VALUE n)
1032
+ {
1033
+ gsl_poly_complex_workspace *w = NULL;
1034
+ w = gsl_poly_complex_workspace_alloc(FIX2INT(n));
1035
+ return Data_Wrap_Struct(klass, 0, gsl_poly_complex_workspace_free, w);
1036
+ }
1037
+
1038
+ #ifdef GSL_1_1_LATER
1039
+
1040
+ /* singleton method of the class Poly */
1041
+ static VALUE rb_gsl_poly_dd_init(VALUE obj, VALUE vxa, VALUE vya)
1042
+ {
1043
+ gsl_vector *xa = NULL, *ya = NULL;
1044
+ gsl_poly *dd = NULL;
1045
+ Data_Get_Struct(vxa, gsl_vector, xa);
1046
+ Data_Get_Struct(vya, gsl_vector, ya);
1047
+ dd = gsl_vector_alloc(xa->size);
1048
+ gsl_poly_dd_init(dd->data, xa->data, ya->data, xa->size);
1049
+ return Data_Wrap_Struct(cgsl_poly_dd, 0, gsl_vector_free, dd);
1050
+ }
1051
+
1052
+ static VALUE rb_gsl_poly_dd_eval(VALUE obj, VALUE xxa, VALUE xx)
1053
+ {
1054
+ gsl_vector *v = NULL;
1055
+ gsl_matrix *m = NULL;
1056
+ gsl_vector *dd = NULL, *xa, *vnew = NULL;
1057
+ gsl_matrix *mnew = NULL;
1058
+ VALUE x, ary;
1059
+ size_t size, i, j;
1060
+ Data_Get_Struct(obj, gsl_vector, dd);
1061
+ CHECK_VECTOR(xxa);
1062
+ Data_Get_Struct(xxa, gsl_vector, xa);
1063
+ switch (TYPE(xx)) {
1064
+ case T_FIXNUM:
1065
+ case T_BIGNUM:
1066
+ case T_FLOAT:
1067
+ return rb_float_new(gsl_poly_dd_eval(dd->data, xa->data, dd->size,
1068
+ NUM2DBL(xx)));
1069
+ break;
1070
+ case T_ARRAY:
1071
+ size = RARRAY_LEN(xx);
1072
+ ary = rb_ary_new2(size);
1073
+ for (i = 0; i < size; i++) {
1074
+ x = rb_ary_entry(xx, i);
1075
+ Need_Float(x);
1076
+ rb_ary_store(ary, i,
1077
+ rb_float_new(gsl_poly_dd_eval(dd->data, xa->data,
1078
+ dd->size, NUM2DBL(x))));
1079
+ }
1080
+ return ary;
1081
+ break;
1082
+ default:
1083
+ if (VEC_P(xx)) {
1084
+ Data_Get_Struct(xx, GSL_TYPE(gsl_vector), v);
1085
+ size = v->size;
1086
+ vnew = gsl_vector_alloc(v->size);
1087
+ for (i = 0; i < size; i++) {
1088
+ gsl_vector_set(vnew, i,
1089
+ gsl_poly_dd_eval(dd->data, xa->data,
1090
+ dd->size, FUNCTION(gsl_vector,get)(v, i)));
1091
+ }
1092
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1093
+ } else if (MAT_P(xx)) {
1094
+ Data_Get_Struct(xx, GSL_TYPE(gsl_matrix), m);
1095
+ size = m->size1;
1096
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1097
+ for (i = 0; i < m->size1; i++) {
1098
+ for (j = 0; j < m->size2; j++) {
1099
+ gsl_matrix_set(mnew, i, j,
1100
+ gsl_poly_dd_eval(dd->data, xa->data,
1101
+ dd->size, gsl_matrix_get(m, i, j)));
1102
+ }
1103
+ }
1104
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1105
+ } else {
1106
+ rb_raise(rb_eTypeError, "wrong argument type");
1107
+ }
1108
+ break;
1109
+ }
1110
+ return Qnil; /* never reach here */
1111
+ }
1112
+
1113
+ static VALUE rb_gsl_poly_dd_taylor(int argc, VALUE *argv, VALUE obj)
1114
+ {
1115
+ gsl_vector *dd = NULL;
1116
+ gsl_vector *xa, *c = NULL, *w = NULL;
1117
+ double xp;
1118
+ size_t size;
1119
+ int flag = 0;
1120
+ Data_Get_Struct(obj, gsl_vector, dd);
1121
+ switch (argc) {
1122
+ case 2:
1123
+ size = dd->size;
1124
+ xp = NUM2DBL(argv[0]);
1125
+ CHECK_VECTOR(argv[1]);
1126
+ Data_Get_Struct(argv[1], gsl_vector, xa);
1127
+ w = gsl_vector_alloc(size);
1128
+ flag = 1;
1129
+ break;
1130
+ case 3:
1131
+ xp = NUM2DBL(argv[0]);
1132
+ CHECK_VECTOR(argv[1]);
1133
+ Data_Get_Struct(argv[1], gsl_vector, xa);
1134
+ if (TYPE(argv[2]) == T_FIXNUM) {
1135
+ size = FIX2INT(argv[2]);
1136
+ w = gsl_vector_alloc(size);
1137
+ flag = 1;
1138
+ } else {
1139
+ CHECK_VEC(argv[2]);
1140
+ Data_Get_Struct(argv[2], GSL_TYPE(gsl_vector), w);
1141
+ size = dd->size;
1142
+ }
1143
+ break;
1144
+ case 4:
1145
+ Need_Float(argv[0]);
1146
+ CHECK_VECTOR(argv[1]);
1147
+ CHECK_FIXNUM(argv[2]);
1148
+ CHECK_VECTOR(argv[3]);
1149
+ xp = NUM2DBL(argv[0]);
1150
+ Data_Get_Struct(argv[1], gsl_vector, xa);
1151
+ size = FIX2INT(argv[2]);
1152
+ Data_Get_Struct(argv[3], GSL_TYPE(gsl_vector), w);
1153
+ break;
1154
+ default:
1155
+ rb_raise(rb_eArgError, "wrong number of arguments");
1156
+ }
1157
+ c = gsl_vector_alloc(size);
1158
+ gsl_poly_dd_taylor(c->data, xp, dd->data, xa->data, size, w->data);
1159
+ if (flag == 1) gsl_vector_free(w);
1160
+ return Data_Wrap_Struct(cgsl_poly_taylor, 0, gsl_vector_free, c);
1161
+ }
1162
+
1163
+ #endif
1164
+ #endif
1165
+
1166
+ static VALUE FUNCTION(rb_gsl_poly,order)(VALUE obj)
1167
+ {
1168
+ GSL_TYPE(gsl_vector) *v = NULL;
1169
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1170
+ return INT2FIX(v->size - 1);
1171
+ }
1172
+
1173
+ int FUNCTION(gsl_poly,conv)(const BASE *a, size_t na, const BASE *b, size_t nb,
1174
+ BASE *c, size_t *nc)
1175
+ {
1176
+ BASE x;
1177
+ size_t i, j;
1178
+ *nc = na + nb - 1;
1179
+ for (i = 0; i < *nc; i++) c[i] = 0;
1180
+ for (i = 0; i < *nc; i++) {
1181
+ if (i >= na) break;
1182
+ x = a[i];
1183
+ for (j = 0; j < *nc; j++) {
1184
+ if (j >= nb) break;
1185
+ else c[i+j] += x*b[j];
1186
+ }
1187
+ }
1188
+ return 0;
1189
+ }
1190
+
1191
+ GSL_TYPE(gsl_vector)* FUNCTION(gsl_poly,conv_vector)(const GSL_TYPE(gsl_vector) *v1, const GSL_TYPE(gsl_vector) *v2)
1192
+ {
1193
+ GSL_TYPE(gsl_vector) *vnew = NULL;
1194
+ size_t n, tmp;
1195
+ if (v1->size == 1) {
1196
+ vnew = FUNCTION(make_vector,clone)(v2);
1197
+ FUNCTION(gsl_vector,scale)(vnew, FUNCTION(gsl_vector,get)(v1, 0));
1198
+ return vnew;
1199
+ } else if (v2->size == 1) {
1200
+ vnew = FUNCTION(make_vector,clone)(v1);
1201
+ FUNCTION(gsl_vector,scale)(vnew, FUNCTION(gsl_vector,get)(v2, 0));
1202
+ return vnew;
1203
+ } else {
1204
+ n = v1->size + v2->size - 1;
1205
+ vnew = FUNCTION(gsl_vector,calloc)(n);
1206
+ FUNCTION(gsl_poly,conv)(v1->data, v1->size, v2->data, v2->size, vnew->data, &tmp);
1207
+ return vnew;
1208
+ }
1209
+ }
1210
+
1211
+ GSL_TYPE(gsl_vector)* FUNCTION(gsl_poly,reduce)(const GSL_TYPE(gsl_vector) *v)
1212
+ {
1213
+ size_t i, nn = v->size;
1214
+ GSL_TYPE(gsl_vector) *vnew = NULL;
1215
+ for (i = v->size-1; 0 <= (int) i; i--) {
1216
+ if (!gsl_fcmp(FUNCTION(gsl_vector,get)(v, i), 0.0, 1e-10)) {
1217
+ nn = i;
1218
+ break;
1219
+ }
1220
+ }
1221
+ if (nn == 0) nn = v->size;
1222
+ vnew = FUNCTION(gsl_vector,alloc)(nn);
1223
+ for (i = 0; i < nn; i++) {
1224
+ FUNCTION(gsl_vector,set)(vnew, i, FUNCTION(gsl_vector,get)(v, i));
1225
+ }
1226
+ return vnew;
1227
+ }
1228
+
1229
+ GSL_TYPE(gsl_vector)* FUNCTION(gsl_poly,deriv)(const GSL_TYPE(gsl_vector) *v)
1230
+ {
1231
+ GSL_TYPE(gsl_vector) *vnew = NULL;
1232
+ size_t i;
1233
+ vnew = FUNCTION(gsl_vector,alloc)(v->size - 1);
1234
+ for (i = 0; i < v->size - 1; i++) {
1235
+ FUNCTION(gsl_vector,set)(vnew, i, FUNCTION(gsl_vector,get)(v, i+1)*(i+1));
1236
+ }
1237
+ return vnew;
1238
+ }
1239
+
1240
+ GSL_TYPE(gsl_vector)* FUNCTION(gsl_poly,integ)(const GSL_TYPE(gsl_vector) *v)
1241
+ {
1242
+ GSL_TYPE(gsl_vector) *vnew = NULL;
1243
+ size_t i;
1244
+ vnew = FUNCTION(gsl_vector,alloc)(v->size + 1);
1245
+ FUNCTION(gsl_vector,set)(vnew, 0, 0.0);
1246
+ for (i = 1; i < v->size + 1; i++) {
1247
+ FUNCTION(gsl_vector,set)(vnew, i, FUNCTION(gsl_vector,get)(v, i-1)/i);
1248
+ }
1249
+ return vnew;
1250
+ }
1251
+
1252
+ GSL_TYPE(gsl_vector)* FUNCTION(gsl_poly,deconv_vector)(const GSL_TYPE(gsl_vector) *c, const GSL_TYPE(gsl_vector) *a,
1253
+ GSL_TYPE(gsl_vector) **r)
1254
+ {
1255
+ GSL_TYPE(gsl_vector) *vnew = NULL, *a2 = NULL, *c2 = NULL, *vtmp = NULL;
1256
+ GSL_TYPE(gsl_vector) *rtmp = NULL;
1257
+ BASE x, y, z, aa;
1258
+ size_t n, i, j, k, jj;
1259
+ c2 = FUNCTION(gsl_poly,reduce)(c);
1260
+ a2 = FUNCTION(gsl_poly,reduce)(a);
1261
+ n = c2->size - a2->size + 1;
1262
+ vnew = FUNCTION(gsl_vector,calloc)(n);
1263
+ rtmp = FUNCTION(gsl_vector,alloc)(c2->size - 1);
1264
+ aa = FUNCTION(gsl_vector,get)(a2, a2->size - 1);
1265
+ FUNCTION(gsl_vector,set)(vnew, n-1, FUNCTION(gsl_vector,get)(c2, c2->size-1)/aa);
1266
+ for (i = n - 2, k = 1; k < n; i--, k++) {
1267
+ x = FUNCTION(gsl_vector,get)(c2, c2->size-1-k);
1268
+ for (j = n-1; j >= 0; j--) {
1269
+ z = FUNCTION(gsl_vector,get)(vnew, j);
1270
+ jj = c2->size-1-k-j;
1271
+ if (jj > k || jj < 0) continue;
1272
+ y = FUNCTION(gsl_vector,get)(a2, jj);
1273
+ x -= y*z;
1274
+ }
1275
+ FUNCTION(gsl_vector,set)(vnew, i, x/aa);
1276
+ }
1277
+ vtmp = FUNCTION(gsl_poly,conv_vector)(vnew, a2);
1278
+ for (i = 0; i < rtmp->size; i++) {
1279
+ x = FUNCTION(gsl_vector,get)(c2, i);
1280
+ y = FUNCTION(gsl_vector,get)(vtmp, i);
1281
+ FUNCTION(gsl_vector,set)(rtmp, i, x - y);
1282
+ }
1283
+ *r = FUNCTION(gsl_poly,reduce)(rtmp);
1284
+ FUNCTION(gsl_vector,free)(rtmp);
1285
+ FUNCTION(gsl_vector,free)(vtmp);
1286
+ FUNCTION(gsl_vector,free)(c2);
1287
+ FUNCTION(gsl_vector,free)(a2);
1288
+ return vnew;
1289
+ }
1290
+
1291
+ GSL_TYPE(gsl_poly)* FUNCTION(get_poly,get)(VALUE obj, int *flag)
1292
+ {
1293
+ GSL_TYPE(gsl_poly) *p = NULL;
1294
+ size_t i;
1295
+ switch (TYPE(obj)) {
1296
+ case T_ARRAY:
1297
+ p = FUNCTION(gsl_vector,alloc)(RARRAY_LEN(obj));
1298
+ for (i = 0; i < p->size; i++) FUNCTION(gsl_vector,set)(p, i, (BASE) NUM2DBL(rb_ary_entry(obj, i)));
1299
+ *flag = 1;
1300
+ break;
1301
+ case T_FLOAT:
1302
+ case T_FIXNUM:
1303
+ p = FUNCTION(gsl_vector,alloc)(1);
1304
+ FUNCTION(gsl_vector,set)(p, 0, (BASE) NUM2DBL(obj));
1305
+ *flag = 1;
1306
+ break;
1307
+ default:
1308
+ CHECK_VEC(obj);
1309
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), p);
1310
+ *flag = 0;
1311
+ break;
1312
+ }
1313
+ return p;
1314
+ }
1315
+
1316
+ static VALUE FUNCTION(rb_gsl_poly,conv)(VALUE obj, VALUE bb)
1317
+ {
1318
+ GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL, *vnew = NULL;
1319
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1320
+ switch (TYPE(bb)) {
1321
+ case T_FIXNUM:
1322
+ case T_FLOAT:
1323
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
1324
+ FUNCTION(gsl_vector,memcpy)(vnew, v);
1325
+ FUNCTION(gsl_vector,scale)(vnew, (BASE) NUM2DBL(bb));
1326
+ break;
1327
+ default:
1328
+ CHECK_VEC(bb);
1329
+ Data_Get_Struct(bb, GSL_TYPE(gsl_vector), v2);
1330
+ vnew = FUNCTION(gsl_poly,conv_vector)(v, v2);
1331
+ break;
1332
+ }
1333
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1334
+ }
1335
+
1336
+ VALUE FUNCTION(rb_gsl_poly,deconv)(VALUE obj, VALUE bb)
1337
+ {
1338
+ GSL_TYPE(gsl_poly) *v = NULL, *v2 = NULL, *vnew = NULL, *r = NULL;
1339
+ int flag = 0;
1340
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1341
+ switch (TYPE(bb)) {
1342
+ case T_ARRAY:
1343
+ v2 = FUNCTION(get_poly,get)(bb, &flag);
1344
+ break;
1345
+ case T_FLOAT:
1346
+ case T_FIXNUM:
1347
+ v2 = FUNCTION(gsl_vector,alloc)(1);
1348
+ FUNCTION(gsl_vector,set)(v2, 0, (BASE) NUM2DBL(bb));
1349
+ break;
1350
+ default:
1351
+ CHECK_VEC(bb);
1352
+ Data_Get_Struct(bb, GSL_TYPE(gsl_vector), v2);
1353
+ break;
1354
+ }
1355
+ vnew = FUNCTION(gsl_poly,deconv_vector)(v, v2, &r);
1356
+ if (flag == 1) FUNCTION(gsl_vector,free)(v2);
1357
+ if (FUNCTION(gsl_vector,isnull)(r))
1358
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1359
+ else
1360
+ return rb_ary_new3(2, Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew),
1361
+ Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), r));
1362
+ }
1363
+
1364
+ static VALUE FUNCTION(rb_gsl_poly,reduce)(VALUE obj)
1365
+ {
1366
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
1367
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1368
+ vnew = FUNCTION(gsl_poly,reduce)(v);
1369
+ if (vnew == NULL) {
1370
+ return Qnil;
1371
+ } else if (vnew->size == 0) {
1372
+ return Qnil;
1373
+ } else if (FUNCTION(gsl_vector,isnull)(vnew)) {
1374
+ return INT2FIX(0);
1375
+ } else if (vnew->size == 1) {
1376
+ return rb_float_new(FUNCTION(gsl_vector,get)(vnew, 0));
1377
+ } else {
1378
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1379
+ }
1380
+ return Qnil; /* never reach here */
1381
+ }
1382
+
1383
+ static VALUE FUNCTION(rb_gsl_poly,deriv)(VALUE obj)
1384
+ {
1385
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
1386
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1387
+ vnew = FUNCTION(gsl_poly,deriv)(v);
1388
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1389
+ }
1390
+
1391
+ static VALUE FUNCTION(rb_gsl_poly,integ)(VALUE obj)
1392
+ {
1393
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
1394
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1395
+ vnew = FUNCTION(gsl_poly,integ)(v);
1396
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1397
+ }
1398
+
1399
+ static VALUE FUNCTION(rb_gsl_poly,conv2)(VALUE klass, VALUE v1, VALUE v2)
1400
+ {
1401
+ GSL_TYPE(gsl_poly) *p1 = NULL, *p2 = NULL, *p3 = NULL;
1402
+ int flag1 = 0, flag2 = 0;
1403
+ size_t i;
1404
+ VALUE ary;
1405
+ p1 = FUNCTION(get_poly,get)(v1, &flag1);
1406
+ p2 = FUNCTION(get_poly,get)(v2, &flag2);
1407
+ p3 = FUNCTION(gsl_poly,conv_vector)(p1, p2);
1408
+ if (flag1 == 1) FUNCTION(gsl_vector,free)(p1);
1409
+ if (flag2 == 1) FUNCTION(gsl_vector,free)(p2);
1410
+ if (flag1 == 1 && flag2 == 1) {
1411
+ ary = rb_ary_new2(p3->size);
1412
+ for (i = 0; i < p3->size; i++)
1413
+ rb_ary_store(ary, i, C_TO_VALUE2(FUNCTION(gsl_vector,get)(p3, i)));
1414
+ FUNCTION(gsl_vector,free)(p3);
1415
+ return ary;
1416
+ } else {
1417
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), p3);
1418
+ }
1419
+ }
1420
+
1421
+ static VALUE FUNCTION(rb_gsl_poly,deconv2)(VALUE klass, VALUE v1, VALUE v2)
1422
+ {
1423
+ GSL_TYPE(gsl_poly) *p1 = NULL, *p2 = NULL;
1424
+ GSL_TYPE(gsl_poly) *r = NULL, *vnew = NULL;
1425
+ int flag1 = 0, flag2 = 0;
1426
+ p1 = FUNCTION(get_poly,get)(v1, &flag1);
1427
+ p2 = FUNCTION(get_poly,get)(v2, &flag2);
1428
+ vnew = FUNCTION(gsl_poly,deconv_vector)(p1, p2, &r);
1429
+ if (flag1 == 1) FUNCTION(gsl_vector,free)(p1);
1430
+ if (flag2 == 1) FUNCTION(gsl_vector,free)(p2);
1431
+ if (FUNCTION(gsl_vector,isnull)(r))
1432
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1433
+ else
1434
+ return rb_ary_new3(2, Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew),
1435
+ Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), r));
1436
+ }
1437
+
1438
+ GSL_TYPE(gsl_poly)* FUNCTION(gsl_poly,add)(const GSL_TYPE(gsl_poly) *a,
1439
+ const GSL_TYPE(gsl_poly) *b)
1440
+ {
1441
+ GSL_TYPE(gsl_poly) *c = NULL;
1442
+ const GSL_TYPE(gsl_poly) *longer;
1443
+ size_t i, n;
1444
+ if (a->size > b->size) {
1445
+ c = FUNCTION(gsl_vector,alloc)(a->size);
1446
+ longer = a;
1447
+ } else {
1448
+ c = FUNCTION(gsl_vector,alloc)(b->size);
1449
+ longer = b;
1450
+ }
1451
+ n = GSL_MIN(a->size, b->size);
1452
+ for (i = 0; i < n; i++) {
1453
+ FUNCTION(gsl_vector,set)(c, i, FUNCTION(gsl_vector,get)(a, i) + FUNCTION(gsl_vector,get)(b, i));
1454
+ }
1455
+ for (i = n; i < c->size; i++)
1456
+ FUNCTION(gsl_vector,set)(c, i, FUNCTION(gsl_vector,get)(longer, i));
1457
+ return c;
1458
+ }
1459
+
1460
+ static VALUE FUNCTION(rb_gsl_poly,add)(VALUE obj, VALUE bb)
1461
+ {
1462
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL, *vb = NULL;
1463
+ BASE b;
1464
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1465
+ switch (TYPE(bb)) {
1466
+ case T_FLOAT:
1467
+ case T_FIXNUM:
1468
+ b = (BASE) NUM2DBL(bb);
1469
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
1470
+ FUNCTION(gsl_vector,memcpy)(vnew, v);
1471
+ FUNCTION(gsl_vector,set)(vnew, 0, FUNCTION(gsl_vector,get)(v, 0) + b);
1472
+ break;
1473
+ default:
1474
+ CHECK_VEC(bb);
1475
+ Data_Get_Struct(bb, GSL_TYPE(gsl_vector), vb);
1476
+ vnew = FUNCTION(gsl_poly,add)(v, vb);
1477
+ }
1478
+ return Data_Wrap_Struct(CLASS_OF(obj), 0, FUNCTION(gsl_vector,free), vnew);
1479
+ }
1480
+
1481
+ static VALUE rb_gsl_poly_uminus(VALUE obj);
1482
+ static VALUE rb_gsl_poly_int_uminus(VALUE obj);
1483
+ static VALUE FUNCTION(rb_gsl_poly,sub)(VALUE obj, VALUE bb)
1484
+ {
1485
+ switch (TYPE(bb)) {
1486
+ case T_FLOAT:
1487
+ case T_FIXNUM:
1488
+ return FUNCTION(rb_gsl_poly,add)(obj, C_TO_VALUE2(-(BASE)NUM2DBL(bb)));
1489
+ break;
1490
+ default:
1491
+ CHECK_VEC(bb);
1492
+ return FUNCTION(rb_gsl_poly,add)(obj, FUNCTION(rb_gsl_poly,uminus)(bb));
1493
+ break;
1494
+ }
1495
+ }
1496
+
1497
+ static VALUE FUNCTION(rb_gsl_poly,uminus)(VALUE obj)
1498
+ {
1499
+ GSL_TYPE(gsl_poly) *p = NULL, *pnew = NULL;
1500
+ size_t i;
1501
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), p);
1502
+ pnew = FUNCTION(gsl_vector,alloc)(p->size);
1503
+ for (i = 0; i < pnew->size; i++) FUNCTION(gsl_vector,set)(pnew, i, -FUNCTION(gsl_vector,get)(p, i));
1504
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), pnew);
1505
+ }
1506
+
1507
+ static VALUE FUNCTION(rb_gsl_poly,uplus)(VALUE obj)
1508
+ {
1509
+ return obj;
1510
+ }
1511
+
1512
+ static VALUE FUNCTION(rb_gsl_poly,coerce)(VALUE obj, VALUE other)
1513
+ {
1514
+ GSL_TYPE(gsl_vector) *vb;
1515
+ switch (TYPE(other)) {
1516
+ case T_FLOAT:
1517
+ case T_FIXNUM:
1518
+ vb = FUNCTION(gsl_vector,calloc)(1);
1519
+ FUNCTION(gsl_vector,set)(vb, 0, (BASE) NUM2DBL(other));
1520
+ return rb_ary_new3(2, Data_Wrap_Struct(CLASS_OF(obj), 0, FUNCTION(gsl_vector,free), vb),
1521
+ obj);
1522
+ break;
1523
+ default:
1524
+ CHECK_VEC(other);
1525
+ return rb_ary_new3(3, other, obj);
1526
+ break;
1527
+ }
1528
+ }
1529
+
1530
+ static VALUE FUNCTION(rb_gsl_poly,to_gv)(VALUE obj)
1531
+ {
1532
+ GSL_TYPE(gsl_vector) *v, *vnew = NULL;
1533
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1534
+ vnew = FUNCTION(make_vector,clone)(v);
1535
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
1536
+ }
1537
+
1538
+ static VALUE FUNCTION(rb_gsl_poly,companion_matrix)(VALUE obj)
1539
+ {
1540
+ GSL_TYPE(gsl_poly) *p = NULL;
1541
+ BASE z;
1542
+ gsl_matrix *m;
1543
+ size_t i, j, size;
1544
+ Data_Get_Struct(obj, GSL_TYPE(gsl_poly), p);
1545
+ size = p->size - 1;
1546
+ m = gsl_matrix_calloc(size, size);
1547
+ z = FUNCTION(gsl_vector,get)(p, size);
1548
+ for (j = 0; j < size; j++)
1549
+ gsl_matrix_set(m, 0, size-j-1, -FUNCTION(gsl_vector,get)(p, j)/z);
1550
+ for (i = 1; i < size; i++) {
1551
+ gsl_matrix_set(m, i, i-1, 1.0);
1552
+ }
1553
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, m);
1554
+ }
1555
+
1556
+ static VALUE FUNCTION(rb_gsl_poly,info)(VALUE obj)
1557
+ {
1558
+ GSL_TYPE(gsl_poly) *v;
1559
+ char buf[256];
1560
+ Data_Get_Struct(obj, GSL_TYPE(gsl_poly), v);
1561
+ sprintf(buf, "Class: %s\n", rb_class2name(CLASS_OF(obj)));
1562
+ #ifdef RUBY_1_9_LATER
1563
+ sprintf(buf, "%sSuperClass: %s\n", buf, rb_class2name(RCLASS_SUPER(CLASS_OF(obj))));
1564
+ #else
1565
+ sprintf(buf, "%sSuperClass: %s\n", buf, rb_class2name(RCLASS(CLASS_OF(obj))->super));
1566
+ #endif
1567
+ sprintf(buf, "%sOrder: %d\n", buf, (int) v->size-1);
1568
+ return rb_str_new2(buf);
1569
+ }
1570
+
1571
+ #ifdef BASE_DOUBLE
1572
+ #include "rb_gsl_fit.h"
1573
+ /* singleton */
1574
+ static VALUE rb_gsl_poly_fit(int argc, VALUE *argv, VALUE obj)
1575
+ {
1576
+ gsl_multifit_linear_workspace *space = NULL;
1577
+ gsl_matrix *X = NULL, *cov = NULL;
1578
+ gsl_vector *x, *y = NULL, *c = NULL;
1579
+ gsl_vector_view xx, yy;
1580
+ size_t order, i, j;
1581
+ double chisq, val;
1582
+ int status, flag = 0;
1583
+ VALUE vc, vcov;
1584
+ if (argc != 3 && argc != 4)
1585
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
1586
+ x = &xx.vector;
1587
+ y = &yy.vector;
1588
+ Data_Get_Vector(argv[0], x);
1589
+ Data_Get_Vector(argv[1], y);
1590
+ order = NUM2INT(argv[2]);
1591
+ if (argc == 4) {
1592
+ Data_Get_Struct(argv[3], gsl_multifit_linear_workspace, space);
1593
+ } else {
1594
+ space = gsl_multifit_linear_alloc(x->size, order + 1);
1595
+ flag = 1;
1596
+ }
1597
+ cov = gsl_matrix_alloc(order + 1, order + 1);
1598
+ c = gsl_vector_alloc(order + 1);
1599
+ X = gsl_matrix_alloc(x->size, order + 1);
1600
+ for (i = 0; i < x->size; i++) {
1601
+ val = 1.0;
1602
+ gsl_matrix_set(X, i, 0, val);
1603
+ for (j = 1; j <= order; j++) {
1604
+ val *= gsl_vector_get(x, i);
1605
+ gsl_matrix_set(X, i, j, val);
1606
+ }
1607
+ }
1608
+ status = gsl_multifit_linear(X, y, c, cov, &chisq, space);
1609
+ if (flag == 1) gsl_multifit_linear_free(space);
1610
+ vc = Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, c);
1611
+ vcov = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, cov);
1612
+ gsl_matrix_free(X);
1613
+ return rb_ary_new3(4, vc, vcov, rb_float_new(chisq), INT2FIX(status));
1614
+ }
1615
+
1616
+ static VALUE rb_gsl_poly_wfit(int argc, VALUE *argv, VALUE obj)
1617
+ {
1618
+ gsl_multifit_linear_workspace *space = NULL;
1619
+ gsl_matrix *X = NULL, *cov = NULL;
1620
+ gsl_vector *x, *y = NULL, *w, *c = NULL;
1621
+ size_t order, i, j;
1622
+ double chisq, val;
1623
+ int status, flag = 0;
1624
+ VALUE vc, vcov;
1625
+ if (argc != 4 && argc != 5)
1626
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc);
1627
+ Data_Get_Vector(argv[0], x);
1628
+ Data_Get_Vector(argv[1], w);
1629
+ Data_Get_Vector(argv[2], y);
1630
+ order = NUM2INT(argv[3]);
1631
+ if (argc == 5) {
1632
+ Data_Get_Struct(argv[4], gsl_multifit_linear_workspace, space);
1633
+ } else {
1634
+ space = gsl_multifit_linear_alloc(x->size, order + 1);
1635
+ flag = 1;
1636
+ }
1637
+ cov = gsl_matrix_alloc(order + 1, order + 1);
1638
+ c = gsl_vector_alloc(order + 1);
1639
+ X = gsl_matrix_alloc(x->size, order + 1);
1640
+ for (i = 0; i < x->size; i++) {
1641
+ val = 1.0;
1642
+ gsl_matrix_set(X, i, 0, val);
1643
+ for (j = 1; j <= order; j++) {
1644
+ val *= gsl_vector_get(x, i);
1645
+ gsl_matrix_set(X, i, j, val);
1646
+ }
1647
+ }
1648
+ status = gsl_multifit_wlinear(X, w, y, c, cov, &chisq, space);
1649
+ if (flag == 1) gsl_multifit_linear_free(space);
1650
+ vc = Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, c);
1651
+ vcov = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, cov);
1652
+ gsl_matrix_free(X);
1653
+ return rb_ary_new3(4, vc, vcov, rb_float_new(chisq), INT2FIX(status));
1654
+ }
1655
+ #endif
1656
+
1657
+ #ifdef BASE_DOUBLE
1658
+ #ifdef GSL_1_13_LATER
1659
+ static VALUE rb_gsl_poly_eval_derivs_singleton(int argc, VALUE *argv, VALUE klass)
1660
+ {
1661
+ VALUE ary;
1662
+ gsl_vector *v = NULL, *v2 = NULL;
1663
+ size_t i, lenc, lenres;
1664
+ #ifdef HAVE_NARRAY_H
1665
+ struct NARRAY *na;
1666
+ double *ptr1, *ptr2;
1667
+ int shape[1];
1668
+ #endif
1669
+
1670
+ if (argc < 2) rb_raise(rb_eArgError, "Wrong number of arguments (%d for >= 2)", argc);
1671
+ if (rb_obj_is_kind_of(argv[0], rb_cArray)) {
1672
+ v = gsl_vector_alloc(RARRAY_LEN(argv[0]));
1673
+ lenc = v->size;
1674
+ for (i = 0; i < lenc; i++) {
1675
+ gsl_vector_set(v, i, NUM2DBL(rb_ary_entry(argv[0], i)));
1676
+ }
1677
+ if (argc == 2) lenres = lenc + 1;
1678
+ else lenres = FIX2INT(argv[2]);
1679
+ v2 = gsl_vector_alloc(lenres);
1680
+ gsl_poly_eval_derivs(v->data, lenc, NUM2DBL(argv[1]), v2->data, lenres);
1681
+ ary = rb_ary_new2(lenres);
1682
+ for (i = 0; i < lenres; i++) {
1683
+ rb_ary_store(ary, i, rb_float_new(gsl_vector_get(v2, i)));
1684
+ }
1685
+ gsl_vector_free(v2);
1686
+ gsl_vector_free(v);
1687
+ return ary;
1688
+ }
1689
+ if (rb_obj_is_kind_of(argv[0], cgsl_vector)) {
1690
+ Data_Get_Struct(argv[0], gsl_vector, v);
1691
+ lenc = v->size;
1692
+ if (argc == 2) lenres = lenc + 1;
1693
+ else lenres = FIX2INT(argv[2]);
1694
+ v2 = gsl_vector_alloc(lenres);
1695
+ gsl_poly_eval_derivs(v->data, lenc, NUM2DBL(argv[1]), v2->data, lenres);
1696
+ return Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, v2);
1697
+ }
1698
+ #ifdef HAVE_NARRAY_H
1699
+ if (NA_IsNArray(argv[0])) {
1700
+ GetNArray(argv[0], na);
1701
+ ptr1 = (double*) na->ptr;
1702
+ lenc = na->total;
1703
+ if (argc == 2) lenres = lenc + 1;
1704
+ else lenres = FIX2INT(argv[2]);
1705
+ shape[0] = lenres;
1706
+ ary = na_make_object(NA_DFLOAT, na->rank, shape, CLASS_OF(argv[0]));
1707
+ ptr2 = NA_PTR_TYPE(ary,double*);
1708
+ gsl_poly_eval_derivs(ptr1, lenc, NUM2DBL(argv[1]), ptr2, lenres);
1709
+ return ary;
1710
+ }
1711
+ #endif
1712
+ return Qnil; // Never comes here
1713
+ }
1714
+ static VALUE rb_gsl_poly_eval_derivs(int argc, VALUE *argv, VALUE obj)
1715
+ {
1716
+ gsl_vector *v, *v2;
1717
+ size_t lenc, lenres;
1718
+ Data_Get_Struct(obj, gsl_vector, v);
1719
+ lenc = v->size;
1720
+ switch (argc) {
1721
+ case 1:
1722
+ lenres = lenc + 1;
1723
+ break;
1724
+ case 2:
1725
+ lenres = FIX2INT(argv[1]);
1726
+ break;
1727
+ default:
1728
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for > 1)", argc);
1729
+ }
1730
+ v2 = gsl_vector_alloc(lenres);
1731
+ gsl_poly_eval_derivs(v->data, lenc, NUM2DBL(argv[0]), v2->data, lenres);
1732
+ return Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, v2);
1733
+ }
1734
+ #endif
1735
+ #endif
1736
+
1737
+ void FUNCTION(Init_gsl_poly,init)(VALUE module)
1738
+ {
1739
+ #ifdef BASE_DOUBLE
1740
+ VALUE mgsl_poly_complex;
1741
+ cgsl_poly = rb_define_class_under(module, "Poly", cgsl_vector);
1742
+ cgsl_poly_int = rb_define_class_under(cgsl_poly, "Int", cgsl_vector_int);
1743
+
1744
+ cgsl_poly_workspace = rb_define_class_under(cgsl_poly, "Workspace", cGSL_Object);
1745
+ mgsl_poly_complex = rb_define_module_under(cgsl_poly, "Complex");
1746
+ cgsl_poly_complex_workspace = rb_define_class_under(mgsl_poly_complex,
1747
+ "Workspace", cGSL_Object);
1748
+ rb_define_singleton_method(cgsl_poly_workspace, "alloc",
1749
+ rb_gsl_poly_workspace_new, 1);
1750
+ rb_define_singleton_method(cgsl_poly_complex_workspace, "alloc",
1751
+ rb_gsl_poly_workspace_new, 1);
1752
+
1753
+ rb_define_singleton_method(mgsl_poly_complex, "solve_quadratic",
1754
+ FUNCTION(rb_gsl_poly,complex_solve_quadratic), -1);
1755
+ rb_define_singleton_method(mgsl_poly_complex, "solve_cubic",
1756
+ FUNCTION(rb_gsl_poly,complex_solve_cubic), -1);
1757
+ #ifdef HAVE_POLY_SOLVE_QUARTIC
1758
+ rb_define_singleton_method(mgsl_poly_complex, "solve_quartic",
1759
+ FUNCTION(rb_gsl_poly,complex_solve_quartic), -1);
1760
+ #endif
1761
+
1762
+ rb_define_singleton_method(mgsl_poly_complex, "solve",
1763
+ FUNCTION(rb_gsl_poly,complex_solve), -1);
1764
+ rb_define_singleton_method(mgsl_poly_complex, "roots",
1765
+ FUNCTION(rb_gsl_poly,complex_solve), -1);
1766
+ #endif
1767
+
1768
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "solve_quadratic",
1769
+ FUNCTION(rb_gsl_poly,solve_quadratic), -1);
1770
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "solve_cubic",
1771
+ FUNCTION(rb_gsl_poly,solve_cubic), -1);
1772
+
1773
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "complex_solve_quadratic",
1774
+ FUNCTION(rb_gsl_poly,complex_solve_quadratic), -1);
1775
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "complex_solve_cubic",
1776
+ FUNCTION(rb_gsl_poly,complex_solve_cubic), -1);
1777
+ #ifdef HAVE_POLY_SOLVE_QUARTIC
1778
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "solve_quartic",
1779
+ FUNCTION(rb_gsl_poly,solve_quartic), -1);
1780
+
1781
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "complex_solve_quartic",
1782
+ FUNCTION(rb_gsl_poly,complex_solve_quartic), -1);
1783
+ #endif
1784
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "complex_solve",
1785
+ FUNCTION(rb_gsl_poly,complex_solve), -1);
1786
+
1787
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "solve",
1788
+ FUNCTION(rb_gsl_poly,complex_solve), -1);
1789
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "roots",
1790
+ FUNCTION(rb_gsl_poly,complex_solve), -1);
1791
+
1792
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "eval",
1793
+ FUNCTION(rb_gsl_poly,eval2), -1);
1794
+
1795
+ rb_define_method(GSL_TYPE(cgsl_poly), "eval",
1796
+ FUNCTION(rb_gsl_poly,eval), 1);
1797
+ rb_define_alias(GSL_TYPE(cgsl_poly), "at", "eval");
1798
+
1799
+ rb_define_method(GSL_TYPE(cgsl_poly), "solve_quadratic",
1800
+ FUNCTION(rb_gsl_poly,solve_quadratic2), 0);
1801
+ rb_define_method(GSL_TYPE(cgsl_poly), "complex_solve_quadratic",
1802
+ FUNCTION(rb_gsl_poly,complex_solve_quadratic2), 0);
1803
+
1804
+ rb_define_method(GSL_TYPE(cgsl_poly), "solve_cubic",
1805
+ FUNCTION(rb_gsl_poly,solve_cubic2), 0);
1806
+ rb_define_method(GSL_TYPE(cgsl_poly), "complex_solve_cubic",
1807
+ FUNCTION(rb_gsl_poly,complex_solve_cubic2), 0);
1808
+
1809
+ #ifdef HAVE_POLY_SOLVE_QUARTIC
1810
+ rb_define_method(GSL_TYPE(cgsl_poly), "solve_quartic",
1811
+ FUNCTION(rb_gsl_poly,solve_quartic2), 0);
1812
+ rb_define_method(GSL_TYPE(cgsl_poly), "complex_solve_quartic",
1813
+ FUNCTION(rb_gsl_poly,complex_solve_quartic2), 0);
1814
+ #endif
1815
+
1816
+ rb_define_method(GSL_TYPE(cgsl_poly), "complex_solve",
1817
+ FUNCTION(rb_gsl_poly,complex_solve2), -1);
1818
+ rb_define_alias(GSL_TYPE(cgsl_poly), "solve", "complex_solve");
1819
+ rb_define_alias(GSL_TYPE(cgsl_poly), "roots", "complex_solve");
1820
+
1821
+ #ifdef BASE_INT
1822
+ rb_define_method(cgsl_poly_int, "to_f", rb_gsl_poly_int_to_f, 0);
1823
+ #endif
1824
+
1825
+ #ifdef BASE_DOUBLE
1826
+ // rb_define_singleton_method(cgsl_poly, "eval", rb_gsl_poly_eval_singleton, 2);
1827
+ rb_define_method(cgsl_poly, "to_i", rb_gsl_poly_to_i, 0);
1828
+ #ifdef GSL_1_11_LATER
1829
+ rb_define_singleton_method(cgsl_poly, "complex_eval", rb_gsl_poly_eval_singleton, 2);
1830
+ rb_define_method(cgsl_vector_complex, "eval", rb_gsl_complex_poly_complex_eval, 1);
1831
+ #endif
1832
+ #ifdef GSL_1_1_LATER
1833
+ cgsl_poly_dd = rb_define_class_under(cgsl_poly, "DividedDifference", cgsl_poly);
1834
+ cgsl_poly_taylor = rb_define_class_under(cgsl_poly, "Taylor", cgsl_poly);
1835
+ rb_define_singleton_method(cgsl_poly, "dd_init", rb_gsl_poly_dd_init, 2);
1836
+
1837
+ rb_define_method(cgsl_poly_dd, "eval",rb_gsl_poly_dd_eval, 2);
1838
+ rb_define_method(cgsl_poly_dd, "taylor", rb_gsl_poly_dd_taylor, -1);
1839
+ #endif
1840
+ #endif
1841
+
1842
+ rb_define_method(GSL_TYPE(cgsl_poly), "order", FUNCTION(rb_gsl_poly,order), 0);
1843
+
1844
+ /*****/
1845
+ rb_define_method(GSL_TYPE(cgsl_poly), "conv", FUNCTION(rb_gsl_poly,conv), 1);
1846
+ rb_define_alias(GSL_TYPE(cgsl_poly), "*", "conv");
1847
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "conv",
1848
+ FUNCTION(rb_gsl_poly,conv2), 2);
1849
+
1850
+ rb_define_method(GSL_TYPE(cgsl_poly), "deconv",
1851
+ FUNCTION(rb_gsl_poly,deconv), 1);
1852
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "deconv",
1853
+ FUNCTION(rb_gsl_poly,deconv2), 2);
1854
+
1855
+ rb_define_method(GSL_TYPE(cgsl_poly), "reduce",
1856
+ FUNCTION(rb_gsl_poly,reduce), 1);
1857
+ rb_define_method(GSL_TYPE(cgsl_poly), "deriv", FUNCTION(rb_gsl_poly,deriv), 1);
1858
+ rb_define_method(GSL_TYPE(cgsl_poly), "integ", FUNCTION(rb_gsl_poly,integ), 1);
1859
+
1860
+ /*****/
1861
+
1862
+ rb_define_method(GSL_TYPE(cgsl_poly), "add", FUNCTION(rb_gsl_poly,add), 1);
1863
+ rb_define_alias(GSL_TYPE(cgsl_poly), "+", "add");
1864
+ rb_define_method(GSL_TYPE(cgsl_poly), "sub", FUNCTION(rb_gsl_poly,sub), 1);
1865
+ rb_define_alias(GSL_TYPE(cgsl_poly), "-", "sub");
1866
+
1867
+ rb_define_method(GSL_TYPE(cgsl_poly), "-@", FUNCTION(rb_gsl_poly,uminus), 0);
1868
+ rb_define_method(GSL_TYPE(cgsl_poly), "+@", FUNCTION(rb_gsl_poly,uplus), 0);
1869
+
1870
+ rb_define_method(GSL_TYPE(cgsl_poly), "coerce",
1871
+ FUNCTION(rb_gsl_poly,coerce), 1);
1872
+ rb_define_method(GSL_TYPE(cgsl_poly), "to_gv", FUNCTION(rb_gsl_poly,to_gv), 0);
1873
+ rb_define_alias(GSL_TYPE(cgsl_poly), "to_v", "to_gv");
1874
+
1875
+ rb_define_method(GSL_TYPE(cgsl_poly), "companion_matrix",
1876
+ FUNCTION(rb_gsl_poly,companion_matrix), 0);
1877
+ rb_define_alias(GSL_TYPE(cgsl_poly), "compan", "companion_matrix");
1878
+
1879
+ /*****/
1880
+ rb_define_method(GSL_TYPE(cgsl_poly), "info",
1881
+ FUNCTION(rb_gsl_poly,info), 0);
1882
+
1883
+ #ifdef BASE_DOUBLE
1884
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "fit",
1885
+ FUNCTION(rb_gsl_poly,fit), -1);
1886
+ rb_define_singleton_method(GSL_TYPE(cgsl_poly), "wfit",
1887
+ FUNCTION(rb_gsl_poly,wfit), -1);
1888
+
1889
+ #ifdef GSL_1_13_LATER
1890
+ rb_define_singleton_method(cgsl_poly, "eval_derivs", rb_gsl_poly_eval_derivs_singleton, -1);
1891
+ rb_define_method(cgsl_vector, "eval_derivs", rb_gsl_poly_eval_derivs, -1);
1892
+ #endif
1893
+
1894
+ #endif
1895
+ }
1896
+
1897
+ #undef NUMCONV
1898
+ #undef NUMCONV2
1899
+ #undef PRINTF_FORMAT
1900
+ #undef VEC_ROW_COL
1901
+ #undef VEC_P
1902
+ #undef C_TO_VALUE
1903
+ #undef C_TO_VALUE2
1904
+ #undef VEC_COL_P
1905
+ #undef VEC_ROW_P
1906
+ #undef CHECK_VEC
1907
+ #undef VEC_VIEW_P
1908
+
1909
+ #undef MAT_ROW_COL
1910
+ #undef MAT_P
1911
+ #undef C_TO_VALUE
1912
+ #undef MAT_COL_P
1913
+ #undef MAT_ROW_P
1914
+ #undef CHECK_MAT
1915
+ #undef MAT_VIEW_P