cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrFnSolver.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 _nmrFnSolver_h
29 #define _nmrFnSolver_h
30 
32 
33 #include <cnetlib.h>
34 
96 class nmrFnSolver {
97  // we have this class so that we reserve memory only one
98  // would help if svd of a same size matrix (or a matrix)
99  // that doesnt change much is desired.
100 
101 protected:
102  CISSTNETLIB_INTEGER N;
103  CISSTNETLIB_DOUBLE Tolerance;
104  CISSTNETLIB_INTEGER Info;
105  CISSTNETLIB_INTEGER Lwork;
107 
108 public:
114  {
115  Allocate(0);
116  }
117 
118 
127  nmrFnSolver(CISSTNETLIB_INTEGER n)
128  {
129  Allocate(n);
130  }
131 
132 
140  Allocate(X);
141  }
143 
144 
151  inline void Allocate(CISSTNETLIB_INTEGER n) {
152  N = n;
153  Lwork = N*(3*3*3*N+13)/2;
154  Tolerance = 1e-6;
155  Work.SetSize(Lwork);
156  }
157 
158 
165  Allocate(X.size());
166  }
168 
169 
178  template <int __instanceLine, class __elementType>
180  vctDynamicVector<CISSTNETLIB_DOUBLE> &F, CISSTNETLIB_DOUBLE tolerance) throw (std::runtime_error) {
181  if ((N != static_cast<CISSTNETLIB_INTEGER>(X.size())) || (N != static_cast<CISSTNETLIB_INTEGER>(F.size()))) {
182  cmnThrow(std::runtime_error("nmrFnSolver Solve: Size used for Allocate was different"));
183  }
184  Tolerance = tolerance;
185  /* call the MINPACK C function */
186  hybrd1_((U_fp)callBack.FunctionFhybrd, &N,
187  X.Pointer(), F.Pointer(),
188  &Tolerance, &Info,
189  Work.Pointer(), &Lwork);
190  }
192 
193 };
194 
195 #endif // _nmrFnSolver_h
196 
Declaration of vctDynamicMatrix.
void Allocate(vctDynamicVector< CISSTNETLIB_DOUBLE > &X)
Definition: nmrFnSolver.h:164
nmrFnSolver(void)
Definition: nmrFnSolver.h:113
void SetSize(size_type size)
Definition: vctDynamicVector.h:315
Definition: nmrFnSolver.h:96
void Allocate(CISSTNETLIB_INTEGER n)
Definition: nmrFnSolver.h:151
nmrFnSolver(CISSTNETLIB_INTEGER n)
Definition: nmrFnSolver.h:127
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
Definition: nmrCallBack.h:45
void Solve(nmrCallBackFunctionF< __instanceLine, __elementType > &callBack, vctDynamicVector< CISSTNETLIB_DOUBLE > &X, vctDynamicVector< CISSTNETLIB_DOUBLE > &F, CISSTNETLIB_DOUBLE tolerance)
Definition: nmrFnSolver.h:179
CISSTNETLIB_INTEGER Info
Definition: nmrFnSolver.h:104
CISSTNETLIB_INTEGER N
Definition: nmrFnSolver.h:102
#define cmnThrow(a)
Definition: MinimalCmn.h:4
CISSTNETLIB_INTEGER Lwork
Definition: nmrFnSolver.h:105
vctDynamicVector< CISSTNETLIB_DOUBLE > Work
Definition: nmrFnSolver.h:106
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
CISSTNETLIB_DOUBLE Tolerance
Definition: nmrFnSolver.h:103
nmrFnSolver(vctDynamicVector< CISSTNETLIB_DOUBLE > &X)
Definition: nmrFnSolver.h:139