# Need help understand the varf command

**URL:** https://community.freefem.org/t/need-help-understand-the-varf-command/4355
**Category:** General Discussion
**Created:** [September 3, 2026, 3:54pm UTC](https://community.freefem.org/t/need-help-understand-the-varf-command/4355 "2026-09-03T15:54:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![EChase](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@EChase](https://community.freefem.org/u/EChase)
#### Post date: [September 3, 2026, 3:54pm UTC](https://community.freefem.org/t/need-help-understand-the-varf-command/4355/1 "2026-09-03T15:54:23Z")

</div>

I am trying to use the varf command to generate a mass matrix for a cylinder, for an axisymmetric problem.

I have been very successful in creating error messages, but not a working mass matrix.

Could you please help identify what it is that I am doing wrong?  
Thank you,

Here is the code:

real R = 4.75_2.54/100; // radius  
real L = 0.1_2.54/100; // length  
int nr = 5, nz = 10; // mesh resolution

// Mesh in (r,z) plane  
mesh Th = square(nr, nz, [R_x, L_y]);

// Finite element space  
fespace Vh(Th, P1);  
Vh u, v;  
Vh uu, vv;  
Vh rr, zz;  
rr = x; // radial coordinates  
zz = y; // axial coordinates

// Axisymmetric mass matrix assembly  
//varf massAxis(u, v) = int2d(Th)( 2_pi_x \* u \* v );  
varf massAxis(u, v) = int2d(Th)(u\*dx(u)\*dy(v));

// Build the matrix  
matrix M = massAxis(Vh, Vh);

// Optional: check size and a sample entry  
// cout \<\< "Mass matrix size: " \<\< M.n \<\< " x " \<\< M.m \<\< endl;

for(int jj=0; jj \< nr; jj++) {  
for(int kk=0; kk \< nz; kk++) {  
cout \<\< "for jj = " \<\< jj \<\< " and kk = " \<\< kk \<\< " M(jj,kk) = " \<\< M(jj,kk) \<\< endl;  
}  
}

real MassSum = 0.0;  
for(int jj=0; jj \< nr; jj++) {  
for(int kk=0; kk \< nz; kk++) {  
MassSum = MassSum + M(jj,kk);  
}  
}

cout \<\< "summation mass matrix " \<\< MassSum \<\< endl;

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [September 4, 2026, 8:12am UTC](https://community.freefem.org/t/need-help-understand-the-varf-command/4355/2 "2026-09-04T08:12:44Z")

</div>

Your variational form must be linear with respect to `u` and to `v`. Here `u*dx(u)` is not linear.
