# A+B and its sparsity

**URL:** <https://community.freefem.org/t/a-b-and-its-sparsity/1094>\
**Category:** General Discussion\
**Created:** [July 12, 2021, 11:40pm UTC](https://community.freefem.org/t/a-b-and-its-sparsity/1094 "2021-07-12T23:40:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [July 12, 2021, 11:40pm UTC](https://community.freefem.org/t/a-b-and-its-sparsity/1094/1 "2021-07-12T23:40:36Z")

</div>

When we add matrix B to A (PETSc Mat), is there a method to drop the non-zero elements in B which **do not** exist in A?

For example, if  
A=  
[ 1, 0  
0, 2]

B=  
[1, -1  
0, 3]

Can we neglect -1 in B, so that B would have the same sparsity as A?

---

<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:** [July 13, 2021, 5:03am UTC](https://community.freefem.org/t/a-b-and-its-sparsity/1094/2 "2021-07-13T05:03:47Z")

</div>

No, you need to do that yourself.

---

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [July 13, 2021, 7:00am UTC](https://community.freefem.org/t/a-b-and-its-sparsity/1094/3 "2021-07-13T07:00:51Z")

</div>

do you have an idea? can I access every element of the matrix?

---

<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:** [July 13, 2021, 8:53am UTC](https://community.freefem.org/t/a-b-and-its-sparsity/1094/4 "2021-07-13T08:53:28Z")

</div>

You can read the [documentation](https://doc.freefem.org/).
