diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-06-05 18:53:07 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-06-05 18:53:07 +0000 |
commit | 49a3d719221cd9484a64688ffcdbeb13cb8e55a0 (patch) | |
tree | fbe5161936acb1f49d1337c2da1f7f93139c089a /examples/root.hs | |
parent | bbc54bf2573ea3631ee436507807dae6c4353bcc (diff) |
check dim in root function
Diffstat (limited to 'examples/root.hs')
-rw-r--r-- | examples/root.hs | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/examples/root.hs b/examples/root.hs index 9a674fd..69db243 100644 --- a/examples/root.hs +++ b/examples/root.hs | |||
@@ -1,27 +1,17 @@ | |||
1 | -- root finding examples | 1 | -- root finding examples |
2 | import Numeric.GSL | 2 | import Numeric.GSL |
3 | import Numeric.LinearAlgebra | 3 | import Numeric.LinearAlgebra |
4 | import Graphics.Plot | ||
5 | import Text.Printf(printf) | 4 | import Text.Printf(printf) |
6 | 5 | ||
7 | rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ] | 6 | rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ] |
8 | 7 | ||
9 | disp = putStrLn . format " " (printf "%.3f") | ||
10 | |||
11 | -- Numerical estimation of the gradient | ||
12 | gradient f v = [partialDerivative k f v | k <- [0 .. length v -1]] | ||
13 | |||
14 | partialDerivative n f v = fst (derivCentral 0.01 g (v!!n)) where | ||
15 | g x = f (concat [a,x:b]) | ||
16 | (a,_:b) = splitAt n v | ||
17 | |||
18 | test method = do | 8 | test method = do |
19 | print method | 9 | print method |
20 | let (s,p) = root method 1E-7 30 (rosenbrock 1 10) [-10,-5] | 10 | let (s,p) = root method 1E-7 30 (rosenbrock 1 10) [-10,-5] |
21 | print s -- solution | 11 | print s -- solution |
22 | disp p -- evolution of the algorithm | 12 | disp p -- evolution of the algorithm |
23 | -- let [x,y] = tail (toColumns p) | 13 | |
24 | -- mplot [x,y] -- path from the starting point to the solution | 14 | disp = putStrLn . format " " (printf "%.3f") |
25 | 15 | ||
26 | main = do | 16 | main = do |
27 | test Hybrids | 17 | test Hybrids |