summaryrefslogtreecommitdiff
path: root/examples/root.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 /examples/root.hs
parente07c3dee7235496b71a89233106d93f6cc94ada1 (diff)
update dependencies, move examples etc
Diffstat (limited to 'examples/root.hs')
-rw-r--r--examples/root.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/root.hs b/examples/root.hs
new file mode 100644
index 0000000..8546ff5
--- /dev/null
+++ b/examples/root.hs
@@ -0,0 +1,31 @@
1-- root finding examples
2import Numeric.GSL
3import Numeric.LinearAlgebra
4import Text.Printf(printf)
5
6rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ]
7
8test method = do
9 print method
10 let (s,p) = root method 1E-7 30 (rosenbrock 1 10) [-10,-5]
11 print s -- solution
12 disp p -- evolution of the algorithm
13
14jacobian a b [x,y] = [ [-a , 0]
15 , [-2*b*x, b] ]
16
17testJ method = do
18 print method
19 let (s,p) = rootJ method 1E-7 30 (rosenbrock 1 10) (jacobian 1 10) [-10,-5]
20 print s
21 disp p
22
23disp = putStrLn . format " " (printf "%.3f")
24
25main = do
26 test Hybrids
27 test Hybrid
28 test DNewton
29 test Broyden
30
31 mapM_ testJ [HybridsJ .. GNewton]