author | Lesley De Cruz <lesley.decruz+git@gmail.com> | 2012年03月04日 00:46:27 +0100 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年03月04日 21:41:31 +0100 |
commit | 750b1a5619b6fc5bcf4e7af84896a8eaf01589d0 (patch) | |
tree | 1433a491abf52498e6926822af72d18030c8f5dd /tests/ode.lua | |
parent | 9c0c6b43eccbb17963a49b74610badcfac5c7445 (diff) | |
download | gsl-shell-auto-test.tar.gz |
-rw-r--r-- | tests/ode.lua | 31 |
diff --git a/tests/ode.lua b/tests/ode.lua new file mode 100644 index 00000000..49daf2aa --- /dev/null +++ b/tests/ode.lua @@ -0,0 +1,31 @@ +-- tests for module ode +use'num' +local tt = {} + +local methods={'rk8pd','rkf45'} + +local function odef(t, x, y) + return -y^2, 2*x - y^3 +end + +-- we define initial values +local t0, t1, h0 = 0, 30, 0.04 +local x0, y0 = 1, 1 + +-- function tests +for i,method in ipairs(methods) do + tt[method] = function(test) + local s = ode{N= 2, eps_abs= 1e-8, method=method} + s:init(t0, h0, odef, x0, y0) + local function f(i) + local t = i*(t1-t0)/10 + while s.t < t do + s:evolve(odef,t) + end + return {s.y[1],s.y[2]} + end + test{iter.ilist(f,10)} + end +end + +return tt |