# Indicator function of a rectangle

**URL:** <https://community.freefem.org/t/indicator-function-of-a-rectangle/2233>\
**Category:** General Discussion\
**Created:** [January 20, 2023, 2:07pm UTC](https://community.freefem.org/t/indicator-function-of-a-rectangle/2233 "2023-01-20T14:07:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca.liverotti](https://avatars.discourse-cdn.com/v4/letter/l/977dab/32.png) [@luca.liverotti](https://community.freefem.org/u/luca.liverotti)\
**Post date:** [January 20, 2023, 2:07pm UTC](https://community.freefem.org/t/indicator-function-of-a-rectangle/2233/1 "2023-01-20T14:07:04Z")

</div>

Hi everyone!  
I tried to implement the indicator function of a rectangle Q as follows

// Q = [xq1,xq2] x [yq1,yq2], xq1\<xq2, yq1\<yq2  
func real chiQ(real xq1,real xq2,real yq1,real yq2){  
if(x\>=xq1 & x\<=xq2 & y\>=yq1 & y\<=yq2) return 1;  
else return 0;  
}

but I think I am wrong with something.  
Indeed, by computing the integral of the indicator function of Q = [0.25,0.75] x [0.25,0.75], I should obtain the area of Q, that is 0.25, but I got results, such as 0.26, 0.22, varying based on the mesh on which I’m computing the integral.  
Here the way I compute this integral:  
cout\<\<int2d(Th) (chiQ(0.25,0.75,0.25,0.75))\<\<endl;

Do you have any idea about why?

---

<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:** [January 21, 2023, 4:41pm UTC](https://community.freefem.org/t/indicator-function-of-a-rectangle/2233/2 "2023-01-21T16:41:57Z")

</div>

Remerber , than if the rectangle is not edges of mesh, you have no chance to get the exact value  
and the precission is in O(h) .
