-
Stephen Smith authored
added to pinv - actually zero singular values if they're less than tol (when inverting them), rather than just leaving them as they are
Stephen Smith authoredadded to pinv - actually zero singular values if they're less than tol (when inverting them), rather than just leaving them as they are
miscmaths.cc 53.90 KiB
/* miscmaths.cc
Mark Jenkinson & Mark Woolrich & Christian Beckmann & Tim Behrens, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
/* CCOPYRIGHT */
// Miscellaneous maths functions
#include "miscmaths.h"
#include "miscprob.h"
#include "stdlib.h"
#include "newmatio.h"
using namespace std;
namespace MISCMATHS {
// The following lines are ignored by the current SGI compiler
// (version egcs-2.91.57)
// A temporary fix of including the std:: in front of all abs() etc
// has been done for now
using std::abs;
using std::sqrt;
using std::exp;
using std::log;
// using std::pow;
using std::atan2;
string size(const Matrix& mat)
{
string str = num2str(mat.Nrows())+"*"+num2str(mat.Ncols());
return str;
}
float Sinc(const float x) {
if (fabs(x)<1e-9) {
return 1-x*x*M_PI*M_PI/6.0;
} else {
return sin(M_PI*x)/(M_PI*x);
}
}
double Sinc(const double x) {
if (fabs(x)<1e-9) {
return 1-x*x*M_PI*M_PI/6.0;
} else {
return sin(M_PI*x)/(M_PI*x);
}
}
// General string/IO functions
bool isnum(const string& str)
{
// assumes that initial whitespace has been removed
if (isdigit(str[0])) return true;
if ( (str[0]=='-') || (str[0]=='+') || (str[0]=='.') ) return true;
return false;
}
string skip_alpha(ifstream& fs)
{
string cline;