/* * linearfitting.cpp - linearly fits a segment of a 1D power spectrum. * * Author: Quanren Xiong * * Copyright (C) 2008 by Boulder Laboratory for 3-Dimensional Electron * Microscopy of Cells ("BL3DEMC") and the Regents of the University of * Colorado. See dist/COPYRIGHT for full copyright notice. * * \$Id\$ */ #include #include #include #include "lapackc.h" #include "linearfitting.h" LinearFitting::LinearFitting(int nRaw): nDim(nRaw) { raw=new double[nRaw]; } LinearFitting::~LinearFitting() { delete[] raw; } void LinearFitting::setRaw(double *rawData) { for(int i=0;iindex2 || index1<0 || index2>(nDim-1) ) return 1; int M=index2-index1+1; int N=nModel; int i, j; double lastMin, xx, val; double inc=1.0/(nDim-1); double *a=(double *)malloc(N*M*sizeof(double)); double *aa=(double *)malloc(N*nDim*sizeof(double)); for( i=0; i 0: the algorithm for computing the SVD failed to converge; * if INFO = i, i off-diagonal elements of an intermediate * bidiagonal form did not converge to zero. */ int INFO=1000; double *sv=(double*)malloc(N*sizeof(double)); // store singular values //negative: so machine precision is used as minimun singular value; double RCOND=-5.0; int RANK=-3; //Solve the minimum norm problem || b- A^T * X ||, //M is the number of rows of A^T, the solution is stored in b. dgelss(&M, &N, &NRHS, a, &M, b, &M, sv, &RCOND, &RANK, work, &LWORK, &INFO); for(i=0;i lastMin) break; xAtMin = xx; lastMin = val; } free(a); free(aa); free(b); free(work); free(sv); return INFO; }