Added a function nlinfit and a wrapper over LM functions - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/matrix.lua
diff options
context:
space:
mode:
authorfrancesco <francesco.bbt@gmail.com>2011年03月15日 12:55:20 +0100
committerfrancesco <francesco.bbt@gmail.com>2011年03月15日 12:55:20 +0100
commit60582ef229f9a57d7f7fd107cd9894a689200a11 (patch)
tree160d144048b0032e2e35d929a75a42f90fe661da /matrix.lua
parentb2d6e7aae94c9d4e4f581594d5de6fd43158c81f (diff)
downloadgsl-shell-60582ef229f9a57d7f7fd107cd9894a689200a11.tar.gz
Added a function nlinfit and a wrapper over LM functions
The new function nlinfit replaces the old functions based on the old C/GSL implementation.
Diffstat (limited to 'matrix.lua')
-rw-r--r--matrix.lua 71
1 files changed, 0 insertions, 71 deletions
diff --git a/matrix.lua b/matrix.lua
index 8d7e6319..d4f4e08b 100644
--- a/matrix.lua
+++ b/matrix.lua
@@ -235,74 +235,3 @@ function gsl.linfit(gener, x, y, w)
end
return f, c
end
-
-local function nlinfitwrapf(fmodel, x, y)
- local n = gsl.dim(y)
- return function(p, f, J)
- for k=1, n do
- local ym = fmodel(p, x[k], J and J:row(k))
- if f then f:set(k, 1, ym - y[k]) end
- end
- end
-
-end
-
-function gsl.nlinfit(f, x, y, p0)
- local N = gsl.dim(y)
- local P = gsl.dim(p0)
- local s = gsl.nlfsolver {fdf= nlinfitwrapf(f, x, y), n= N, p0= p0}
- s:run()
- return function(x) return f(s.p, x) end, s.p
-end
-
-function gsl.ode(spec)
- local required = {N= 'number', eps_abs= 'number'}
- local defaults = {eps_rel = 0, a_y = 1, a_dydt = 0}
- local is_known = {rkf45= true, rk8pd= true}
-
- for k, tp in pairs(required) do
- if type(spec[k]) ~= tp then
- error(string.format('parameter %s should be a %s', k, tp))
- end
- end
- for k, v in pairs(defaults) do
- if not spec[k] then spec[k] = v end
- end
-
- local method = spec.method and spec.method or 'rkf45'
- if not is_known[method] then error('unknown ode method: ' .. method) end
- spec.method = nil
-
- local ode = template.load(string.format('num/%s.lua.in', method), spec)
-
- local ode_methods = {
- evolve = function(s, f, t)
- s._sync = false
- return ode.evolve(s._state, f, t)
- end,
- init = function(s, t0, h0, f, ...)
- s._sync = false
- return ode.init(s._state, t0, h0, f, ...)
- end
- }
-
- local ODE = {__index= function(s, k)
- if k == 't' then return s._state.t end
- if k == 'y' then
- if not s._sync then
- for k=1, s.dim do
- s._y[k] = s._state.y[k-1]
- end
- s._sync = true
- end
- return s._y
- end
- return ode_methods[k]
- end}
-
- local dim = spec.N
- local solver = {_state = ode.new(), dim= dim, _y = gsl.new(dim,1)}
- setmetatable(solver, ODE)
-
- return solver
-end
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月15日 03:49:49 +0000

AltStyle によって変換されたページ (->オリジナル) /