haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

odeSolve gives fewer results than expected #183

Closed idontgetoutmuch closed 8 years ago

idontgetoutmuch commented 8 years ago
> foo :: Double -> [Double] -> [Double]
> foo _t [x] = [x]
> 
> fol :: Matrix Double
> fol = odeSolve foo [1.0] (fromList [1.0,2.0,3.0])

gives

*Main> fol
(3><1)
 [                1.0
 , 2.7182818018006936
 ,   7.38905594879871 ]

I.e. we get the solution at time 0 and the solution at times 1 and 2 but not at time 3.

albertoruiz commented 8 years ago

The initial value is X[t[0]], not X[0].

We get the same solution as GNU-Octave:

Xt0 = 1;
t = [1 2 3]';
r = lsode( @(X,t) X, Xt0, t);
[t r]

ans =

   1.0000   1.0000
   2.0000   2.7183
   3.0000   7.3891
idontgetoutmuch commented 8 years ago

My bad - thanks for the explanation

albertoruiz commented 8 years ago

No problem, thanks for testing!