Quick Help with loop modification

I need to modify the "second if statement" in the code shown below as follow: I've 350 values for vp and idx, and would like to calculate Vp2 (tmp+) at each i for 350 and sum all these values of Vp2 and then go to the second values of idy loop for 350 time and so on and I need idy to be double starting from 0,0.1,0.5,1,5,10,.....10000 The tables in the link below explain how should the loop work after modification

http://imgur.com/fjDjHFM (the same results in the link are shown below)

The program after modification should work like this:

Vp2(tmp+) at idy=0	Vp2(tmp+) at idy=0.1	Vp2(tmp+) at idy=0.5	          …….etc
1	                         1	                 1                  	  …….etc
2	                         2	                 2	                  …….etc
3	                         3	                 3	                  …….etc
:	                         :	                 :	                  …….etc
350	                        350	                 350	                  …….etc
sum=	                        sum=	                 sum=	                  …….etc






And The output should also be printed in txt file and should look like:
idy (t)    	 Vp2(t)
0	         sum at idy =0
0.1	         sum at idy =0.1
0.5	         sum at idy =0.5
1	         sum at idy =1
5	         sum at idy =5
10	         sum at idy =10
:	         :


An the code is:

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
	tc=948.0*(dx[0]*dx[0]/4.0*ct*mio*phi/_k1)/24.0;
	double finite_volume =4.0*pai*h*tc*_k1/(3792.0*ct*mio);
	val = my.at(0);
	int idx = 0;
	//double idy = 0;
	Vp2.push_back(0.0);
	tmp = 0.0;
	for(i=0;i<npixels;i++)
	{
		if(val < my.at(i))
		{
			if (i <= tc)
			{
				tmp += 4.0*pai*h*idx*_k1/(3792.0*ct*mio);
				Vp2.push_back(tmp);
			}
			else
			{		
				if(idx >= 1 && Vp[idx-1] >= 4*pai*h*tc*_k1/(3792*ct*mio))
					//if(idx >0)
				{
					//tmp+=4*pai*h*tc*_k1/(3792*ct*mio)+ 0.5*(Vp[idx]-Vp[idx-1])*(exp(-0.25*(t_[idx]*t_[idx])/idx)+exp(-0.25*(t_[idx-1]*t_[idx-1])/idx));
					//tmp+=0.5*(Vp[idx]-Vp[idx-1])*(exp(-0.25*0.25*(t_[idx]+t_[idx-1])*(t_[idx]+t_[idx-1])/idx));
					tmp+=0.5*(Vp[idx]-Vp[idx-1])*(exp(-0.25*(t_[idx]*t_[idx])/idy)+exp(-0.25*(t_[idx-1]*t_[idx-1])/idy)); // modification is needed as explained in email
					Vp2.push_back(tmp);
				}				
			}		
			idx++;	
		}
		//idy++;
		val=my.at(i);
	}

Last edited on
Topic archived. No new replies allowed.