# How to create a rectangle matrix to link two state vectors about different dof?

**URL:** https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585
**Category:** General Discussion
**Created:** [July 6, 2023, 2:36pm UTC](https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585 "2023-07-06T14:36:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)
#### Post date: [July 6, 2023, 2:36pm UTC](https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585/1 "2023-07-06T14:36:06Z")

</div>

Dear all,  
These days I met a problem to create the matrx P to link two state vectors q1 and q2, where q1 includes the degree of freedom about the velocity and pressure, while q2 only the degree of freedom about the velocity. The rectangle matrix P can remove the pressure-related dof in the q1.

![c66a843b292a9a64467117bf39646aa](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/2/241f8b2fb2792dd772914e8446a499849c630874.png)

How could I make the matrix P and output it from the FreeFem++?  
Thanks very much !

---

<div class="post-metadata">

### Author: ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)
#### Post date: [July 6, 2023, 5:05pm UTC](https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585/2 "2023-07-06T17:05:15Z")

</div>

```auto
cat forum226.edp
matrix a,b;
a=[[1,0],[0,1],[0,0]];
cout<<a;
int[int] r=[0,0,1,1,2,2];
int[int] c=[0,1,0,1,0,1];
real[int] v=[1,0,0,1,0,0];
b=[r,c,v];
cout<<b;

```

---

<div class="post-metadata">

### Author: ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)
#### Post date: [July 7, 2023, 4:08am UTC](https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585/3 "2023-07-07T04:08:39Z")

</div>

Thanks for your reply， but I want to do flow instability analysis A(q1)=(omega)B(q1), and I get matrix A and B for the lineariszed NS equation with defined ‘varf’. But now I want to do A(q1)=(omega)B(q1)+(P’)(q2), so l need the matrix for P. It seems that I can not define a ‘varf’ with two different fespace…

And I can’t define a rectangle matrix with only 0 and 1, because I think P includes the mass matrix of fem… or I need to define both P and M(mass matrix of fem) so that A(q1)=(omega)B(q1)+(P’)(M)(q2), so that P only includes 0 and 1. But I don’t know how to only set the dof of pressure is 0, because I don’t know how the dof is ordered in the vectro q1.

---

<div class="post-metadata">

### Author: ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)
#### Post date: [July 7, 2023, 9:10am UTC](https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585/4 "2023-07-07T09:10:32Z")

</div>

Is this what you are looking for?

```auto
mesh Th;
fespace Xh(Th, [P2, P2]);
fespace XMh(Th, [P2, P2, P1]);
Xh<complex> [q2X, q2Y];
XMh<complex> [q1X, q1Y, q1p];
varf vP([q2X, q2Y], [q1X, q1Y, q1p]) = int2d(Th)( q2X*q1X + q2Y*q1Y );
matrix<complex> P = vP(Xh, XMh);

```

---

<div class="post-metadata">

### Author: ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)
#### Post date: [July 10, 2023, 4:04am UTC](https://community.freefem.org/t/how-to-create-a-rectangle-matrix-to-link-two-state-vectors-about-different-dof/2585/5 "2023-07-10T04:04:04Z")

</div>

Thanks ~ I make it in your way!
