#include #include #include using std::cout; using std::pow; using std::sqrt; // #include // #include // #include // #include //using std::ifstream; //using std::istringstream; //using std::vector; //using std::string; //using std::stod; //using std::copy; int main() { double x[] = {0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.0, 4.25, 4.5, 4.75}; double y[] = {1.5891700001638700, 1.2046979031630900, 2.598484110379440, 2.2043375760987900, 3.002229375836470, 2.928655222350250, 3.4769844321649000, 4.007335261529810, 4.534192485682100, 5.76185759925369, 6.41954394976063, 6.023919923933230, 7.443742735575060, 7.870686775946450, 8.022587710435350, 9.395420889477870, 9.948288024421440, 9.986332770533490, 9.694674681091840, 10.519384785632700}; double sig[] = {0.5320185951347170, 0.45427229254919400, 0.5077027054798450, 0.5205826529502230, 0.4698090780151540, 0.4773624121076510, 0.5018787752525470, 0.4897362325985810, 0.49462141854510300, 0.5405394898833090, 0.4523449367708450, 0.48898047501417500, 0.5342659697011440, 0.4730380798563350, 0.4572104512757930, 0.49902577926821200, 0.530527413902035, 0.48969676619036700, 0.5443240285483060, 0.47616567472190800}; //if saved file is existed /* string tmp; std::ifstream fin; fin.open("line.dat"); vector xv; vector yv; vector sigv; vector sv; string sbf; while(!fin.eof()) { getline(fin, tmp); if(tmp == "") {break;} istringstream ss(tmp); while(getline(ss,sbf,',')) { sv.emplace_bacK(); } sv.shrink_to_fit(); xv.emplace_back(stod(sv[0])); yv.emplace_back(stod(sv[1])); sigv.emplace_back(stod(sv[2])); sv.clear(); sv.shrink_to_fit(); } xv.shrink_to_fit(); yv.shrink_to_fit(); sigv.shrink_to_fit(); double x[xv.capacity()]; double y[yv.capacity()]; double sig[sig.capacity()]; copy(xv.begin(), xv.end(), x); copy(yv.begin(), yv.end(), y); copy(sigv.begin(), sigv.end(), sig); */ for(int i = 0; i < sizeof(sig)/sizeof(double); ++i) { sig[i] = 1/sig[i]; } double a, b, cov00, cov01, cov11, chisq; gsl_fit_wlinear(x, 1, sig, 1, y, 1, sizeof(x)/sizeof(double), &b, &a, &cov00, &cov01, &cov11, &chisq); cout << "y = " << a << "x + "<< b << "\n"; }