summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-06-05 18:53:07 +0000
committerAlberto Ruiz <aruiz@um.es>2009-06-05 18:53:07 +0000
commit49a3d719221cd9484a64688ffcdbeb13cb8e55a0 (patch)
treefbe5161936acb1f49d1337c2da1f7f93139c089a /examples
parentbbc54bf2573ea3631ee436507807dae6c4353bcc (diff)
check dim in root function
Diffstat (limited to 'examples')
-rw-r--r--examples/root.hs14
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
2import Numeric.GSL 2import Numeric.GSL
3import Numeric.LinearAlgebra 3import Numeric.LinearAlgebra
4import Graphics.Plot
5import Text.Printf(printf) 4import Text.Printf(printf)
6 5
7rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ] 6rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ]
8 7
9disp = putStrLn . format " " (printf "%.3f")
10
11-- Numerical estimation of the gradient
12gradient f v = [partialDerivative k f v | k <- [0 .. length v -1]]
13
14partialDerivative 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
18test method = do 8test 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 14disp = putStrLn . format " " (printf "%.3f")
25 15
26main = do 16main = do
27 test Hybrids 17 test Hybrids