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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
float math (float f2, float f4,float f22, float f42, float theta)
{
//this function does the w(theta) calculation
float wtheta = 0 ;
wtheta = 1 + f2*f22*1/2*(3* pow(cos(theta),2) *-1 )
+ f4*f42* 1/8*(35*pow(cos(theta),4)
- 30 *pow(cos(theta),4) + 3);
return (wtheta);
}
int main ()
{
//FILLING DATA ARRAYS
// ask user for dat file
start:
cout << "Input filename where the raw data exist-->";
char filename [50];
ifstream dat;
cin.getline(filename,50);
dat.open(filename);
// if file isnt there report error
if (!dat.is_open()){
cout << "File Does Not Exist!" << endl ;
goto start;
}
// read from file and fill arrays
float theta[20], wthe[20], errwth[20];
int x = 0;
float a,b,c,d,e,f;
while (! dat.eof()){
dat >> a >> b >> c;
theta [x] = a ;
wthe [x] = b;
errwth [x] = c;
cout << theta[x] << endl;//check to see if filled right
x++;
}
dat.close();
// SECOND ARRAY FILLING
// fill arrays for testing models
beg:
cout << "Input filename where the data table exist-->";
char file [50];
ifstream table;
cin.getline(file,50);
table.open(file);
// if file isnt there report error
if (!table.is_open()){
cout << "File Does Not Exist!" << endl ;
goto beg;
}
x = 0 ;
float ji [10], jm [10], jf[10], l1[10], l2[10] ;
float f2[10] , f4[10] ;
while (! table.eof()){
table >> a >> b >> c >> d >> e >> f;
jf [x] = a;
ji [x] = b;
l1 [x] = c;
l2 [x] = d;
f2 [x] = e;
f4 [x] = f;
cout << jf [x] << endl;
x++;
}
/*
// testing calls not in a subroutine to check if calc is correct
float mwtheta ;
mwtheta = 1 + f2[0]*f2[1]*1/2*(3* pow(cos(theta[0]),2) *-1 )
+ f4[0]*f4[1]* 1/8*(35*pow(cos(theta[0]),4)
- 30 *pow(cos(theta[0]),4) + 3);
cout << mwtheta << endl;
*/
// call subroutine to do the model wtheta calcs
cout << " Below are the subtracted values (data - model) of wthetas" << endl;
for ( x = 0 ; x < 10 ; x++ ){
float ans;
ans = math (f2[0],f4[0],f2[1],f4[1], theta[x] );
// cout << ans << endl;
float final = wthe[x] - ans ;
cout << final << endl;
}
return 0 ;
}
|