summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-03-27 17:32:30 +0000
committerAlberto Ruiz <aruiz@um.es>2010-03-27 17:32:30 +0000
commitbd1de48eb723b792cad02ecd8f4434078552839b (patch)
treefc21dea76d55957b91a1fb6ee4a7e6273454f397 /examples
parentadc7249bbe8c6648fbe327dea2077ffb84195673 (diff)
interface to Levenberg-Marquardt
Diffstat (limited to 'examples')
-rw-r--r--examples/fitting.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/fitting.hs b/examples/fitting.hs
new file mode 100644
index 0000000..8298c52
--- /dev/null
+++ b/examples/fitting.hs
@@ -0,0 +1,24 @@
1-- nonlinear least-squares fitting
2
3import Numeric.GSL.Fitting
4import Numeric.LinearAlgebra
5
6xs = map return [0 .. 39]
7sigma = 0.1
8ys = map return $ toList $ fromList (map (head . expModel [5,0.1,1]) xs)
9 + scalar sigma * (randomVector 0 Gaussian 40)
10
11dat :: [([Double],[Double],Double)]
12
13dat = zipWith3 (,,) xs ys (repeat sigma)
14
15expModel [a,lambda,b] [t] = [a * exp (-lambda * t) + b]
16
17expModelDer [a,lambda,b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1]]
18
19(sol,path) = fitModel 1E-4 1E-4 20 (resM expModel, resD expModelDer) dat [1,0,0]
20
21main = do
22 print dat
23 print path
24 print sol