Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
// Utility routines that allow the user to check accuracy of their own grad and hess functions
pair<ColumnVector,ColumnVector> check_grad(const ColumnVector& par,
const NonlinCF& cfo)
{
pair<ColumnVector,ColumnVector> rv;
rv.first = cfo.NonlinCF::grad(par);
rv.second = cfo.grad(par);
return(rv);
}
pair<boost::shared_ptr<BFMatrix>,boost::shared_ptr<BFMatrix> > check_hess(const ColumnVector& par,
const NonlinCF& cfo)
{
pair<boost::shared_ptr<BFMatrix>,boost::shared_ptr<BFMatrix> > rv;
rv.first = cfo.NonlinCF::hess(par);
rv.second = cfo.hess(par);
return(rv);
}
void print_newmat(const NEWMAT::GeneralMatrix& m,
std::string fname)
{
if (!fname.length()) {
cout << endl << m << endl;
}
else {
try {
std::ofstream fout(fname.c_str());
fout << setprecision(10) << m;
}
catch(...) {
std::string errmsg("print_newmat: Failed to write to file " + fname);
throw NonlinException(errmsg);
}
}
}
} // End namespace MISCMATHS