File: root.hs

package info (click to toggle)
haskell-hmatrix 0.15.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 608 kB
  • ctags: 302
  • sloc: haskell: 4,909; ansic: 2,688; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 686 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- root finding examples
import Numeric.GSL
import Numeric.LinearAlgebra
import Text.Printf(printf)

rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ]

test method = do
    print method
    let (s,p) = root method 1E-7 30 (rosenbrock 1 10) [-10,-5]
    print s -- solution
    disp p -- evolution of the algorithm

jacobian a b [x,y] = [ [-a    , 0]
                     , [-2*b*x, b] ]

testJ method = do
    print method
    let (s,p) = rootJ method 1E-7 30 (rosenbrock 1 10) (jacobian 1 10) [-10,-5]
    print s
    disp p

disp = putStrLn . format "  " (printf "%.3f")

main = do
    test Hybrids
    test Hybrid
    test DNewton
    test Broyden

    mapM_ testJ [HybridsJ .. GNewton]