# Coefficients of basis functions

**URL:** <https://community.freefem.org/t/coefficients-of-basis-functions/106>\
**Category:** General Discussion\
**Created:** [August 8, 2019, 12:29pm UTC](https://community.freefem.org/t/coefficients-of-basis-functions/106 "2019-08-08T12:29:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fotios.kasolis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fotios.kasolis/32/18_2.png) [@fotios.kasolis](https://community.freefem.org/u/fotios.kasolis)\
**Post date:** [August 8, 2019, 12:29pm UTC](https://community.freefem.org/t/coefficients-of-basis-functions/106/1 "2019-08-08T12:29:00Z")

</div>

Dear community,

Is there a clever way to access the exact coefficients of the P1 basis functions?

Regards,  
/Fotios Kasolis

---

<div class="post-metadata">

**Author:** ![arousta](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@arousta](https://community.freefem.org/u/arousta)\
**Post date:** [August 8, 2019, 9:23pm UTC](https://community.freefem.org/t/coefficients-of-basis-functions/106/2 "2019-08-08T21:23:40Z")

</div>

By using the [] operator:  
fespace Vh(Th,P1);  
Vh f;  
for(int i=0; i\<Vh.ndof; ++i)  
cout\<\<f[][i]\<\<"\n";

---

<div class="post-metadata">

**Author:** ![fotios.kasolis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fotios.kasolis/32/18_2.png) [@fotios.kasolis](https://community.freefem.org/u/fotios.kasolis)\
**Post date:** [August 8, 2019, 10:41pm UTC](https://community.freefem.org/t/coefficients-of-basis-functions/106/3 "2019-08-08T22:41:44Z")

</div>

Dear @arousta,

Unfortunately, this is not right. This way you can only get the components of a finite element function. What I need is something like

```auto
border C(t = 0.0, 2.0*pi){ x = cos(t); y = sin(t); }
mesh T = buildmesh(C(100));

fespace V1(T, P1);
fespace V0(T, P0);
V1 f = 0.0;
V0 a, b;

for (int cnt=0; cnt<V1.ndof; cnt++) {
  f[][cnt] = 1;
  a = dx(f);
  b = dy(f);
  f[][cnt] = 0;
}

```

where `a` and `b` are the required values. I just want to avoid the loop, since these values are somewhere computed in the base code (somehow), and my mesh has 1e7 elements. On the other hand, something like `varf acoef(void,v)=int2d(T)(dx(v))` has to be computed on V1 but can be made to result in average coefficients.
