# How write code of product of average in FreeFem++

**URL:** <https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583>\
**Category:** General Discussion\
**Created:** [November 15, 2024, 7:19pm UTC](https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583 "2024-11-15T19:19:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)\
**Post date:** [November 15, 2024, 7:19pm UTC](https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583/1 "2024-11-15T19:19:29Z")

</div>

Hi, i am getting a term as following:

intalledges(Th) ((average(v1_vv1) +average(v2_vv2)) /nTonEdge\*(nTonEdge-1)) , where v1, v2 are unkowns and vv1 and vv2 are test functions.

How, incorporate this term in FreeFem++??.

---

<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:** [November 21, 2024, 8:06am UTC](https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583/2 "2024-11-21T08:06:40Z")

</div>

Sorry the average of product in not implemented, but if the fonction are P1 you have just use a quadrature with 1 point

---

<div class="post-metadata">

**Author:** ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)\
**Post date:** [November 21, 2024, 8:51am UTC](https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583/3 "2024-11-21T08:51:47Z")

</div>

Respected professor, can you give details code of this term if the function v1, vv1, v2, and vv2 are all in Vh(Th, P1dc) and also what will be that term if all v1, vv1, v2, and vv2 are in Vh(Th, P2dc). In addition, if the space Vh(Th, P3dc) then what will be that term code sir??. I need details code of that term so that no error comes on FreeFem++.

I need a general codes so that i can implement it for any P^k polynomials sir.

Thanks for your replies sir.

---

<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:** [November 21, 2024, 9:38am UTC](https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583/4 "2024-11-21T09:38:57Z")

</div>

If I understand well, by average you mean half the sum of the two values on each side of the edge.  
For a single function u this is mean(u)=(u\_1+u\_2)/2 where the indices 1 and 2 refer to the two sides of the edge.  
Now if you have the product mean(u\*v), you can use the quadratic identity  
\frac{u\_1v\_1+u\_2v\_2}{2}=\frac{u\_1+u\_2}{2}\frac{v\_1+v\_2}{2} +\frac{u\_2-u\_1}{2}\frac{v\_2-v\_1}{2}  
Hence `mean(u*v)=mean(u)*mean(v)+jump(u)*jump(v)/4.`  
This formula is directly usable in FreeFem

---

<div class="post-metadata">

**Author:** ![Monirul25](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/monirul25/32/3287_2.png) [@Monirul25](https://community.freefem.org/u/Monirul25)\
**Post date:** [November 21, 2024, 10:32am UTC](https://community.freefem.org/t/how-write-code-of-product-of-average-in-freefem/3583/5 "2024-11-21T10:32:09Z")

</div>

Thank you so much dear professor.
