//Linda Mac Phee //Feb 96 //This program calculates the time it take s molecules //of ammonia to leave the bottle and arrive a meter away //in a density strong enough to smell //volume of sphere 4/3II(01)^3 == 4/3II(dr)^3 //area of ammonia surface II(dr)^2 //volume of all other shells 4IIR^2dr //function librarys #include //globals #define PI 3.1415 #define TM 2 //past and current time #define SHELL 100 //.5 cm distances from origin int main( void ) { //declare variables int i, j; //loop control int p, m; //loop control double in, out; //temp holding for calculations double n0; //number molecules coming off surface double r0; //inner sphere double r1; //1st shell double dr; //change in shell size double data_array[TM][SHELL]; //1st row temp holding //2nd row current //columns are shells (distance from origin) //initalize variables r0 = .5; //cm r1 = 1.5; //cm dr = 0.5; //cm n0 = 100000; //# molecules for(i=0; i<2; i++){ for(j=0; j<100; j++){ data_array[i][j] = 0; }//end j loop }//end i loop //*****watch don't go off ends of array //time step loop //want 100,000 iterations for(m=0; m < 10; m++){ //copy data for next step and dump //copy from 1st row to oth row for(p = 0; p < SHELL; p++){ data_array[0][p] = data_array[1][p]; }//end for loop transfering data //step through shells loop //100 iterations through all shells to 1 meter //or until 0 which ever is first for(p=0; (p < 10); p++){ //if shell is innermost if(p == 0){ printf("\n iteration # %d ",m); in = ((.375)*(n0) + (1/9)*(data_array[0][1])); out = ((.375)*(data_array[0][0]) + (.75)*(data_array[0][0])); data_array[1][p] = in - out; }//end if inner most shell //if 1st shell if(p == 1){ in = ((.75)*(data_array[0][0]) + (.16)*(data_array[0][2])); out = ((1/9)*(data_array[0][1]) + (4/9)*(data_array[0][1])); data_array[1][1] = in - out; }//end if 1st shell //all other shells if(p > 1){ in = (p*p)/((p-.5)*(p-.5))*(data_array[0][p-1]) + ((p+1)*(p+1))/((p + 1.5)*(p + 1.5))*(data_array[0][p+1]); out = (p*p)/((p+.5)*(p*.5))*(data_array[0][p]) + ((p+1)*(p+1))/((p+.5)*(p+.5))*(data_array[0][p]); data_array[1][p] = (.25 * in) - (.25 * out); }//end if all other shells printf ( " %ld", (long)data_array[1][p]); }//end inside loop }//end outer for loop } //end function