Cannot subtract values from elements of a vector

Hello,

I would like to perform an operation with vectors, but I lost my way. Help would be appreciated.

The operation is, vv = v -(alpha +1)*i; where v and vv are vectors. I need to subtract (alpha +1 ) * i from each element of the vector v, and define those subtracted elements inside my vector vv.


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
  int main ()
{
	const int N = 16 * 2;
	double eta = 0.25;
	const double alpha = 1.2;  //these are constants i use.

	complex w(0.0, 1.0); //Defining a complex number here.
	double z = w.im();   //using its imaginary part.

    const double MAX_ELEMS = N * eta;
    const double MAXIM_ELEMS = N;

	vector<double> vv;
	vector<double> v;

	 
  	  for (double i = 0; v.size() < MAX_ELEMS; i += eta) 
  {
		  v.push_back(i);  
		  for (double j = v.at(1) - (alpha + 1)*z ; vv.size() < MAXIM_ELEMS; j = v.at(i++))
		  {	
			  vv.push_back(j);
		  }
	  }
	 
	  // Want to print my vv vector, at the end of this calculation.

  cout << "my vv vector contains:";
  
  for (unsigned i = 0; i < vv.size(); i++)
    cout << ' ' << vv.at(i);
  cout << '\n';

  return 0;
}
You are saying one thing but in the code you are doing another thing. You should decide at first what you are going to do.
I am pretty new to programming, so my code should be wrong. Indeed what I want to do is to get

vv = v - (alpha + 1) * i,

where v is a vector 0 ---> (N-1) * eta, with eta increments. Could you maybe point out to my mistakes ?

I will need to use these two vectors later on for other calculations as well.
Last edited on
I still need help with this, anyone?
1
2
3
4
5
6
7
8
9
10
vector<double> vv;
vv.reserve( N );
vector<double> v;
v.reserve( N );

for ( int i = 0; i < N; i++ )
{
   v.push_back( i * eta );
   vv.push_back( v.back() - ( alpha + 1 ) * i );
}
Indeed it works, thank you very much!


Topic archived. No new replies allowed.