1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
using namespace std;
#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>
void noisedata(int, double[], double[], double[]);
int main() {
char skiplines [220];
int i;
double dc[4], gt[25], snr[25];
double dval;
cout<<"Linear regression results of snr vs. gt: snr = gt*slope + intercept\n\n";
cout<<"dc (atoms/cc*10e-17) slope intercept r-squared\n";
cout<<"----------------------------------------------------------------\n";
ifstream indata("noisedata.txt");
for (i=0;i<43;i++)
{
indata.getline (skiplines, 220);
}
for (i=0;i<33;i++)
{
indata>>dc[i]>>gt[i]>>snr[i];
}
//cout<<setprecision(2)<<setw(8)<<dc[i]<<setprecision(2)<<setw(8)<<a[i]<<
//setprecision(2)<<setw(8)<<b[i]<<setprecision(6)<<setw(8)rsquared[i]<<endl;
cout<<"Please input a design value for snr between 1 and 100: \n";
cin>>dval; //dval is double value
system("pause");
return 0;
}
void noisedata(int i, double a[], double b[], double rsquared[])
//void function, to determine the slopes (a[i]) intercepts (b[i]), and rsquared[i]
//of the best fit lines of snr(y) vs. gt(x) for each value of dc (There are FIVE values of DC)
// the void fun. passes by reference arrays a[i], b[i], rsquared[i] and their values back to the main program.
// the void function prints out a well formatted screen to a file named results.txt
//snr[x]=a[i]gt+b[i]
//gt[i]=(snrinput - b[i])/a[i]
{
double snr[i], gt[i];
for(i=0;i<4;i++)
{
a[i]=(snr[i])/(gt[i]);
b[i]=gt[i]*a[i];
rsquared[i]=
|