Getting 1.#INF

Hi all,

I'm running some code that calculates a function for a wide range of temperatures. When running the programme my output file gives 1.#INF as qVproduct for each T. qVproduct is calculated the number of times equal to num_modes which is calculated earlier in the code. I looked this up and apparently it could be down to an overflow or dividing by 0. However, I can't seem to work out where in my code the issue is coming from. If anybody could have a look and point me in the right direction I would be extremely grateful :)

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
vector <double> 
		nu(num_modes,0.0);
	for (int i=0; i<num_modes; i++){
	cout << "Enter spectroscopic frequency in cm-1 for mode: " << i << endl;
	cin >> nu[i];
	}


	vector <double> 
		theta(num_modes,0.0);
	for (int i=0; i<num_modes; i++){
		theta[i] = (h*nu[i]/k); // Calculates the characteristic temperature for vibration
		
	}
	double qVproduct = 1.0;
	ofstream output("qV_valuesB_molecule.txt",std::ios::app);
	vector <double> 
		qV(num_modes,0.0);
	for (double T=Tmin; T<=Tmax; T+=Tinc)
	    {
	       for (int i=0; i<=num_modes; i++)
			{
				qV[i] = exp(-theta[i]/(2*T))/(1-exp(-theta[i]/T));
			}
			for (int i=0; i<num_modes+1; i++)
			  {
				
				qVproduct = qVproduct*qV[i];
				
			   }
			output << T << "\t" << qVproduct << endl;
	     }
In your nested loop, "i" seems to go 1 iteration too far.
Since qV only has num_modes elements, both your loops should be
 
for (int i=0; i<num_modes; i++)


Also, you could check if theta[i]/T can be 0 (ie T is equal to 1.#INF or theta[i] is equal to 0).
Hi toum,

I can see what you mean with the loop and i've already attempted a change for that but that gives the outputs for the first 10 temperatures as:
300	-3.4068e-279
301	0
302	-0
303	0
304	-0
305	0
306	-0
307	0
308	-0
309	0
310	-0


where the first qV for T=300 is impossible and the rest are illogical.
I really can't see whats going wrong with this.
could you display the values of theta ?
Topic archived. No new replies allowed.