# How to create eigenvector for an eigen value in MATLAB

**URL:** https://community.freefem.org/t/how-to-create-eigenvector-for-an-eigen-value-in-matlab/2936
**Category:** General Discussion
**Created:** [February 7, 2024, 6:42am UTC](https://community.freefem.org/t/how-to-create-eigenvector-for-an-eigen-value-in-matlab/2936 "2024-02-07T06:42:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Amitkaush](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/amitkaush/32/1978_2.png) [@Amitkaush](https://community.freefem.org/u/Amitkaush)
#### Post date: [February 7, 2024, 6:42am UTC](https://community.freefem.org/t/how-to-create-eigenvector-for-an-eigen-value-in-matlab/2936/1 "2024-02-07T06:42:46Z")

</div>

I am new to FreeFem and am trying to plot eigenvector for v in matlab.  
the freefem++ code is:

real Mj=0.9; // mach number

complex I = 1i;  
real ga=1.4; //gamma  
real M2=(1/(ga_Mj_Mj));  
real Re;  
cout\<\<“Enter Reynold’s number”\<\<endl;  
cin\>\>Re;  
real om,alp,bet;  
// defining the type of stability problem

int a,b;  
cout\<\<“Enter 1 for spatial stability and 2 for temporal stability\n”\<\<endl;  
cin\>\> a;

if(a==1)  
{  
cout\<\<“Enter wave frequency\n”\<\<endl;  
cin\>\>om;}  
else{  
cout\<\<“Enter streamwise wave number\n”\<\<endl;  
cin\>\>alp;  
cout\<\<“Enter spanwise wave number\n”\<\<endl;  
cin\>\>bet;}  
mesh Th;  
int m=300;  
real h=1./m;  
Th=square(1,m);  
Th = emptymesh(Th);

fespace Vh(Th,P2,periodic=[[2,y],[4,y],[1,x],[3,x]]);  
fespace Mh(Th,P1,periodic=[[2,y],[4,y],[1,x],[3,x]]);  
fespace Gh(Th,[P2,P2,P2,P1]);

Vh W,Wy;

Vh u,v,w,a1,a2,a3;  
Mh p,a4;

W=2\*y-1;

Wy=2;

real lambda=(10^18);  
matrixA1;  
matrix B1;  
cout\<\<“Welcome\n”;  
real sigma=0.0006;  
real lamb=10^10;  
varf A([u,v,w,p],[a1,a2,a3,a4])=int2d(Th)(a1\*(W_bet-I_(alp^2+bet^2)/(Re))_u-I_(1/Re)_dy(a1)dy(u)+a1alp_p+  
a2\*(W_bet-I_(alp^2+bet^2)/(Re))_v-I_(1/Re)_dy(a2)dy(v)+Idy(a2)p  
+a3Wy_w+a3_w_(W_bet-I_(alp^2+bet^2)/(Re))-I\*(1/Re)_dy(a3)dy(w)+a3bet_p-sigma_a1_u-sigma_a2_v-sigma_a3_w +a4_alp_u-I_a4_dy(v)+a4_bet_w )+on(1,3,u=0,v=0,w=0);

```
              varf B([u,v,w,p],[a1,a2,a3,a4])=int2d(Th)(a1*u+a2*v+a3*w); 
              
              
              
                A1=A(Gh,Gh);
               B1=B(Gh,Gh);
              ofstream file("A1.csv");

```

for (int i = 0; i \< A1.m; i++) {  
for (int j = 0; j \< A1.n; j++) {  
if(imag(A1(i,j))\>0){file\<\<real(A1(i,j))\<\<“+”\<\<imag(A1(i,j))\<\<“i”;}  
else{file\<\<real(A1(i,j))\<\<imag(A1(i,j))\<\<“i”;}  
if (j \< A1.m - 1) {  
file\<\< “,”;  
}  
}  
file \<\< endl;  
}

```
       ofstream file1("B1.csv");

```

for (int i = 0; i \< B1.n; ++i) {  
for (int j = 0; j \< B1.m; ++j) {  
if(imag(B1(i,j))\>0){file1\<\<real(B1(i,j))\<\<“+”\<\<imag(B1(i,j))\<\<“i”;}  
else{file1\<\<real(B1(i,j))\<\<imag(B1(i,j))\<\<“i”;}  
if (j \< B1.m - 1) {  
file1\<\< “,”;  
}  
}  
file1\<\< endl;  
}

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [February 7, 2024, 9:10am UTC](https://community.freefem.org/t/how-to-create-eigenvector-for-an-eigen-value-in-matlab/2936/2 "2024-02-07T09:10:17Z")

</div>

Some remark on you script:

1. You save your 2 matrix in complex but this matrix a real ???
2. FreeFEM can compute eigen vector and eigen value so with you need matlab except for verification.

---

<div class="post-metadata">

### Author: ![Amitkaush](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/amitkaush/32/1978_2.png) [@Amitkaush](https://community.freefem.org/u/Amitkaush)
#### Post date: [February 9, 2024, 4:50pm UTC](https://community.freefem.org/t/how-to-create-eigenvector-for-an-eigen-value-in-matlab/2936/3 "2024-02-09T16:50:53Z")

</div>

No matrices are complex, I want to use MATLAB as I am more comfortable with it. Also my eigenvalues are not converging in 8000 iterations
