Reputation: 582
#include <stdio.h>
#include <math.h>
int iii;
double E_[100], t_[100], length, lowest_temp, acceptance;
int main(int argc, char *argv[]) {
length=(double)20;
lowest_temp=(double)0.20; /* setting lowest temperature */
acceptance=(double)0.50; /* Acceptance i--> j */
E_[10]=(double)1.3; /*starting E */
t_[0]=lowest_temp;
for(iii>=11;iii<=length-1;iii++){/*CB2*/
E_[10]=1.3;
E_[iii]=E_[iii-1]+(E_[iii-1]/10);
/*Can change 10 to other percentage or random number */
printf("E_[%i]=%f\n",iii,E_[iii]);
}/*CB2*/
for(iii<=9;iii>=0;iii--){/*CB3*/
E_[10]=1.3;
E_[iii]=E_[iii+1]-(E_[iii+1]/10);
printf("E_[%i]=%f\n",iii,E_[iii]);
}/*CB3*/
for(iii=0;iii<=length-1;iii++){/*CB4*/
t_[iii+1]=-((int)1/(t_[iii]))-(log(acceptance)/(E_[iii]+E_[iii+1]));
printf("t_[%i]=%f\n",iii,t_[iii]);
}/*CB4*/
When I run the code I get the following print out:
E_[0]=0.000000
E_[1]=0.000000
E_[2]=0.000000
E_[3]=0.000000
E_[4]=0.000000
E_[5]=0.000000
E_[6]=0.000000
E_[7]=0.000000
E_[8]=0.000000
E_[9]=0.000000
E_[10]=0.000000
E_[11]=1.430000
E_[12]=1.573000
E_[13]=1.730300
E_[14]=1.903330
E_[15]=2.093663
E_[16]=2.303029
E_[17]=2.533332
E_[18]=2.786665
E_[19]=3.065332
E_[20]=0.000000
E_[19]=0.000000
E_[18]=0.000000
E_[17]=0.000000
E_[16]=0.000000
E_[15]=0.000000
E_[14]=0.000000
E_[13]=0.000000
E_[12]=0.000000
E_[11]=0.000000
E_[10]=0.000000
E_[9]=1.170000
E_[8]=1.053000
E_[7]=0.947700
E_[6]=0.852930
E_[5]=0.767637
E_[4]=0.690873
E_[3]=0.621786
E_[2]=0.559607
E_[1]=0.503647
E_[0]=0.453282
t_[0]=0.200000
t_[1]=-4.275654
t_[2]=0.885794
t_[3]=-0.542211
t_[4]=2.372348
t_[5]=0.053720
t_[6]=-18.187354
t_[7]=0.439930
t_[8]=-1.926635
t_[9]=0.830847
t_[10]=-0.922965
t_[11]=1.616655
t_[12]=inf
t_[13]=inf
t_[14]=inf
t_[15]=inf
t_[16]=inf
t_[17]=inf
t_[18]=inf
t_[19]=inf
My objective is to populate the t_[iii] array using the computed E_[iii] array. In order to generate the E_[iii] array I take a pre-existing E_[iii] value from elsewhere in the code (1.3 in this case), then either side of this create for E_[iii>10] values greater than E_[10] and correspondingly below create for E_[iii<10] values less than E_[10].
Arbitrarily I set this to ten percent lower for adjacent E values. Using this I successfully generate the correct values either side of E_[10] however I cannot generate them within the same loop and it seems to be resetting the unused iii indices to zero as can be seen from the print outs.
I would very much appreciate any help in this issue!
Upvotes: 0
Views: 48
Reputation: 352
One problem: for-loop initialisation. At CB2
and CB3
, the iii>=11
and iii<=9
expressions don't initialise iii
.
Upvotes: 1