# Computing scalar product using Mat object

**URL:** <https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244>\
**Category:** General Discussion\
**Created:** [March 27, 2026, 4:42am UTC](https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244 "2026-03-27T04:42:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc2025](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@marc2025](https://community.freefem.org/u/marc2025)\
**Post date:** [March 27, 2026, 4:42am UTC](https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244/1 "2026-03-27T04:42:54Z")

</div>

Hello,

I was reading [this response](https://community.freefem.org/t/usage-of-petscs-mat-type/835/2) on another post, which mentions using a Mat object to compute a scalar product. For example, given:  
`real[int] v;`  
`Mat J;`  
`J(v, v);`

then, as the response says, “`J(v, v)` computes a scalar product according to the domain decomposition of `J`.”

I’m curious as to why `J(v,v)` gives the scalar product? Is this a mathematical property, or is it more a feature of FreeFem / PETSc? Does this always work for any Mat object we create?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 27, 2026, 5:12am UTC](https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244/2 "2026-03-27T05:12:27Z")

</div>

It’s just a notation. It works with any `Mat` as long as it comes from a domain-decomposed mesh (i.e., it was built using `MatCreate()`).

---

<div class="post-metadata">

**Author:** ![marc2025](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@marc2025](https://community.freefem.org/u/marc2025)\
**Post date:** [March 27, 2026, 7:29am UTC](https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244/3 "2026-03-27T07:29:35Z")

</div>

Thank you @prj for the response!  
Is there any mathematical reasoning behind that notation? I just wasn’t sure if there was an intuitive way to understand why something like `J(v,v)` would give a scalar product.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 27, 2026, 9:49am UTC](https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244/4 "2026-03-27T09:49:45Z")

</div>

You could think of it as the scalar product weighted by the partition of unity held by the `Mat`: v^{T} J\text{.D} v.

---

<div class="post-metadata">

**Author:** ![marc2025](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@marc2025](https://community.freefem.org/u/marc2025)\
**Post date:** [March 28, 2026, 6:54am UTC](https://community.freefem.org/t/computing-scalar-product-using-mat-object/4244/5 "2026-03-28T06:54:34Z")

</div>

That makes sense, thank you for your help!
