Problem to use the Eigen header

Hi every body

I am new in C++, and I am trying to use Eigen with very simple code. I firstly tried with the code
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
  #include <iostream>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;

VectorXf CreateZe(const Ref<const VectorXf> Ne)
{
  VectorXf zeta=1/Ne[0]*Ne;
  VectorXf zetaInverse(Ne.rows()); 
  
  for(int i(0);i<(Ne.rows());i++){zetaInverse[i]=(1/zeta[i]);}
  
return zetaInverse;
}


int main()
{
   Matrix2f M;
   M << -5e-4,5e-4,1e-4,-1e-4;
   
   Vector2f n_e;
   n_e << 4,5;
   
   Vector2f Ne;
   Ne<<2000,1000;

   Vector2f zetaInverse=CreateZe(Ne);
   
   cout << "zetaInverse \n";
   cout<< zetaInverse << endl;
   

}


but when I tried to add a second parameter for a very simple operation I got an error :

reateZeFunction.cpp:34:32: error: ‘ne’ was not declared in this scope
Vector2f BeVect=CreateZe(Ne,ne);
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
36
37
38
39
40
41
42
#include <iostream>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;

VectorXf CreateZe(const Ref<const VectorXf> Ne,const Ref<const VectorXf> ne)
{
 
  VectorXf zeta=1/Ne[0]*Ne;
  VectorXf zetaInverse(Ne.rows()); 
  VectorXf BeVect(Ne.rows());

  for(int i(0);i<(Ne.rows());i++){zetaInverse[i]=(1/zeta[i]);}

  for (int i(0);i<(Ne.rows());i++){
   BeVect[i]=zetaInverse[i]*n_e[i];
  }
  return BeVect;

}


int main()
{
   Matrix2f M;
   M << -5e-4,5e-4,1e-4,-1e-4;
   
   Vector2f n_e;
   n_e << 4,5;
   
   Vector2f Ne;
   Ne<<2000,1000;

   Vector2f BeVect=CreateZe(Ne,ne);
   
   
   
   cout << "BeVect \n";
   cout<< BeVect << endl;
   

}


Thank for your help in advance
You haven't created a variable named 'ne' in main().
Vector2f BeVect=CreateZe(Ne,ne);

What's ne? There is no such variable. You never made an object named ne
Thank you I see. I put n_e instead of ne.
Topic archived. No new replies allowed.