From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- math/nlfit/nlsolve.gx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 math/nlfit/nlsolve.gx (limited to 'math/nlfit/nlsolve.gx') diff --git a/math/nlfit/nlsolve.gx b/math/nlfit/nlsolve.gx new file mode 100644 index 00000000..a4055520 --- /dev/null +++ b/math/nlfit/nlsolve.gx @@ -0,0 +1,41 @@ +include +$if (datatype == r) +include "nlfitdefr.h" +$else +include "nlfitdefd.h" +$endif + +# NLSOLVE -- Procedure to solve nonlinear system + +procedure nlsolve$t (nl, ier) + +pointer nl # pointer to the nlfit structure +int ier # error code + +int nfree + +begin + # Make temporary arrays. + call amov$t (ALPHA(NL_ALPHA(nl)), COVAR(NL_COVAR(nl)), + NL_NFPARAMS(nl) ** 2) + call amov$t (BETA(NL_BETA(nl)), DPARAM(NL_DPARAM(nl)), NL_NFPARAMS(nl)) + + # Add the lambda damping factor. + call nl_damp$t (COVAR(NL_COVAR(nl)), COVAR(NL_COVAR(nl)), + (1.0 + NL_LAMBDA(nl)), NL_NFPARAMS(nl), NL_NFPARAMS(nl)) + + ier = OK + nfree = NL_NPTS(nl) - NL_NFPARAMS(nl) + if (nfree < 0) { + ier = NO_DEG_FREEDOM + return + } + + # Compute the factorization of the matrix. + call nl_chfac$t (COVAR(NL_COVAR(nl)), NL_NFPARAMS(nl), NL_NFPARAMS(nl), + CHOFAC(NL_CHOFAC(nl)), ier) + + # Solve the equations for the parameter increments. + call nl_chslv$t (CHOFAC(NL_CHOFAC(nl)), NL_NFPARAMS(nl), NL_NFPARAMS(nl), + DPARAM(NL_DPARAM(nl)), DPARAM(NL_DPARAM(nl))) +end -- cgit