cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrLSNonLinSolver.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ankur Kapoor
7  Created on: 2004-10-26
8 
9  (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 
28 #ifndef _nmrLSNonLinSolver_h
29 #define _nmrLSNonLinSolver_h
30 
31 
34 
36 
37 //include <cnetlib.h>
38 
124  // we have this class so that we reserve memory only one
125  // would help if svd of a same size matrix (or a matrix)
126  // that doesnt change much is desired.
127 
128 protected:
129  CISSTNETLIB_INTEGER M;
130  CISSTNETLIB_INTEGER N;
131  CISSTNETLIB_DOUBLE Tolerance;
132  CISSTNETLIB_INTEGER Info;
133  CISSTNETLIB_INTEGER Lwork;
136 
137 public:
143  {
144  Allocate(0, 0);
145  }
146 
147 
157  nmrLSNonLinSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
158  {
159  Allocate(m, n);
160  }
161 
162 
170  Allocate(X, F);
171  }
173 
174 
182  inline void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n) {
183  M = m;
184  N = n;
185  Lwork = M * N + 5 * N + M;
186  Tolerance = 1e-6;
187  Work.SetSize(Lwork);
188  IWork.SetSize(N);
189  }
190 
191 
198  Allocate(X.size(), F.size());
199  }
201 
202 
210  template <int __instanceLine, class __elementType>
212  vctDynamicVector<CISSTNETLIB_DOUBLE> &F, CISSTNETLIB_DOUBLE tolerance) throw (std::runtime_error) {
213  if ((N != static_cast<CISSTNETLIB_INTEGER>(X.size())) || (M != static_cast<CISSTNETLIB_INTEGER>(F.size()))) {
214  cmnThrow(std::runtime_error("nmrLSNonLinSolver Solve: Size used for Allocate was different"));
215  }
216  Tolerance = tolerance;
217  /* call the MINPACK C function */
218  lmdif1_((U_fp)callBack.FunctionFlmdif, &M, &N,
219  X.Pointer(), F.Pointer(),
220  &Tolerance, &Info,
221  IWork.Pointer(), Work.Pointer(), &Lwork);
222  }
224 
225 };
226 
227 
228 #endif // _nmrLSNonLinSolver_h
229 
Declaration of nmrCallBackLSNonLinSolver.
Declaration of vctDynamicMatrix.
CISSTNETLIB_INTEGER Lwork
Definition: nmrLSNonLinSolver.h:133
Definition: nmrLSNonLinSolver.h:123
void SetSize(size_type size)
Definition: vctDynamicVector.h:315
CISSTNETLIB_INTEGER Info
Definition: nmrLSNonLinSolver.h:132
nmrLSNonLinSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
Definition: nmrLSNonLinSolver.h:157
CISSTNETLIB_INTEGER M
Definition: nmrLSNonLinSolver.h:129
Declaration of vctDynamicVector.
CISSTNETLIB_DOUBLE Tolerance
Definition: nmrLSNonLinSolver.h:131
nmrLSNonLinSolver(vctDynamicVector< CISSTNETLIB_DOUBLE > &X, vctDynamicVector< CISSTNETLIB_DOUBLE > &F)
Definition: nmrLSNonLinSolver.h:169
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
Definition: nmrCallBack.h:45
nmrLSNonLinSolver(void)
Definition: nmrLSNonLinSolver.h:142
vctDynamicVector< CISSTNETLIB_INTEGER > IWork
Definition: nmrLSNonLinSolver.h:134
vctDynamicVector< CISSTNETLIB_DOUBLE > Work
Definition: nmrLSNonLinSolver.h:135
#define cmnThrow(a)
Definition: MinimalCmn.h:4
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
CISSTNETLIB_INTEGER N
Definition: nmrLSNonLinSolver.h:130
void Allocate(vctDynamicVector< CISSTNETLIB_DOUBLE > &X, vctDynamicVector< CISSTNETLIB_DOUBLE > &F)
Definition: nmrLSNonLinSolver.h:197
void Solve(nmrCallBackFunctionF< __instanceLine, __elementType > &callBack, vctDynamicVector< CISSTNETLIB_DOUBLE > &X, vctDynamicVector< CISSTNETLIB_DOUBLE > &F, CISSTNETLIB_DOUBLE tolerance)
Definition: nmrLSNonLinSolver.h:211
void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
Definition: nmrLSNonLinSolver.h:182