summaryrefslogtreecommitdiff
path: root/packages/gsl/src/Numeric/GSL/Polynomials.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-21 10:30:55 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-21 10:30:55 +0200
commit197e88c3b56d28840217010a2871c6ea3a4dd1a4 (patch)
tree825be9d6c9d87d23f7e5497c0133d11d52c63535 /packages/gsl/src/Numeric/GSL/Polynomials.hs
parente07c3dee7235496b71a89233106d93f6cc94ada1 (diff)
update dependencies, move examples etc
Diffstat (limited to 'packages/gsl/src/Numeric/GSL/Polynomials.hs')
-rw-r--r--packages/gsl/src/Numeric/GSL/Polynomials.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/packages/gsl/src/Numeric/GSL/Polynomials.hs b/packages/gsl/src/Numeric/GSL/Polynomials.hs
new file mode 100644
index 0000000..b1be85d
--- /dev/null
+++ b/packages/gsl/src/Numeric/GSL/Polynomials.hs
@@ -0,0 +1,57 @@
1{- |
2Module : Numeric.GSL.Polynomials
3Copyright : (c) Alberto Ruiz 2006
4License : GPL
5Maintainer : Alberto Ruiz
6Stability : provisional
7
8Polynomials.
9
10<http://www.gnu.org/software/gsl/manual/html_node/General-Polynomial-Equations.html#General-Polynomial-Equations>
11
12-}
13
14
15module Numeric.GSL.Polynomials (
16 polySolve
17) where
18
19import Data.Packed
20import Numeric.GSL.Internal
21import Data.Complex
22import System.IO.Unsafe (unsafePerformIO)
23
24#if __GLASGOW_HASKELL__ >= 704
25import Foreign.C.Types (CInt(..))
26#endif
27
28{- | Solution of general polynomial equations, using /gsl_poly_complex_solve/.
29
30For example, the three solutions of x^3 + 8 = 0
31
32>>> polySolve [8,0,0,1]
33[(-2.0) :+ 0.0,1.0 :+ 1.7320508075688776,1.0 :+ (-1.7320508075688776)]
34
35
36The example in the GSL manual: To find the roots of x^5 -1 = 0:
37
38>>> polySolve [-1, 0, 0, 0, 0, 1]
39[(-0.8090169943749472) :+ 0.5877852522924731,
40(-0.8090169943749472) :+ (-0.5877852522924731),
410.30901699437494756 :+ 0.9510565162951535,
420.30901699437494756 :+ (-0.9510565162951535),
431.0000000000000002 :+ 0.0]
44
45-}
46polySolve :: [Double] -> [Complex Double]
47polySolve = toList . polySolve' . fromList
48
49polySolve' :: Vector Double -> Vector (Complex Double)
50polySolve' v | dim v > 1 = unsafePerformIO $ do
51 r <- createVector (dim v-1)
52 app2 c_polySolve vec v vec r "polySolve"
53 return r
54 | otherwise = error "polySolve on a polynomial of degree zero"
55
56foreign import ccall unsafe "gsl-aux.h polySolve" c_polySolve:: TV (TCV Res)
57