# How to get Matrix^-1 \* Matrix in Schur-complement

**URL:** https://community.freefem.org/t/how-to-get-matrix-1-matrix-in-schur-complement/4114
**Category:** General Discussion
**Created:** [October 26, 2025, 10:15am UTC](https://community.freefem.org/t/how-to-get-matrix-1-matrix-in-schur-complement/4114 "2025-10-26T10:15:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Guo.q.q](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@Guo.q.q](https://community.freefem.org/u/Guo.q.q)
#### Post date: [October 26, 2025, 10:15am UTC](https://community.freefem.org/t/how-to-get-matrix-1-matrix-in-schur-complement/4114/1 "2025-10-26T10:15:25Z")

</div>

Hello members and developers of the FreeFEM：

While testing the Schur-complement method for solving a certain matrix(My thoughts are shown in the attachment), I noticed that FreeFEM++ does not support operations like Matrix^-1 \* Matrix. so i modified the approach to use Matrix^-1 \* real[int] instead, but this is undoubtedly very time-consuming—andthe numerical results confirm this. Is this method effectively impractical in FreeFEM?Additionally, I tried loading the “lapack” and “Schur-Complement” modules, but in both cases, the computation time was so longer than that of direct solution methods.

I would truly appreciate your guidance on this matter.

My program schematic:

Solve the following equation:  
//[A B] [X1] = F ;  
//[C D] [X2] = G ;  
//========================  
//Schur method  
//========================  
set(A, solver=sparsesolver);

//step(1) G-C_A^-1_F (G=0)  
real[int] KinvF = Kfix^-1 \* F;  
real[int] CKinvF = C \* KinvF;

//step(2) -C_A^-1_B+D (D=0)  
matrix KinvB(B.n, B.m);for (int i = 0; i \< B.m; i++) {  
real[int] bi(B.n);  
for (int j = 0; j \< B.n; j++) {  
bi[j] = B(j, i);  
}  
real[int] xi = Kfix^-1 \* bi;

```
for (int j = 0; j < B.n; j++) {
    KinvB(j, i) = xi\[j\];  
}

```

}

matrix S = -1\*C \* KinvB;

//step(3) S\*X = H  
set(S, solver=sparsesolver);  
real[int] X = S^-1 \* CKinvF;

//===================  
// time  
//===================  
Matrix A decompose time: 0.376S  
step(1) calculate time: 0.107S  
step(2) calculate time: 249.371S  
step(3) calculate time: 107.208S

---

<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: [October 26, 2025, 2:35pm UTC](https://community.freefem.org/t/how-to-get-matrix-1-matrix-in-schur-complement/4114/2 "2025-10-26T14:35:16Z")

</div>

If you use PETSc, this can be done automatically for you, see, e.g., [PCFieldSplitSetSchurFactType — PETSc 3.24.0 documentation](https://petsc.org/release/manualpages/PC/PCFieldSplitSetSchurFactType/).

---

<div class="post-metadata">

### Author: ![Guo.q.q](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@Guo.q.q](https://community.freefem.org/u/Guo.q.q)
#### Post date: [October 27, 2025, 2:25am UTC](https://community.freefem.org/t/how-to-get-matrix-1-matrix-in-schur-complement/4114/3 "2025-10-27T02:25:55Z")

</div>

Thank you for your response, Professor.  
I have carefully read and studied the materials you provided, which has given me a better understanding of the subject.  
However, since I have limited knowledge and practical experience with PETSc, I would like to further inquire: For my specific problem—using the A-PHI method to compute the electromagnetic field of an electric motor, while incorporating stator-rotor interface coupling, which requires solving at each time step—would this approach likely lead to a significant speedup compared to the direct method in FreeFEM (e.g., set(K, solver=sparsesolver);)?

---

<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: [October 27, 2025, 5:16am UTC](https://community.freefem.org/t/how-to-get-matrix-1-matrix-in-schur-complement/4114/4 "2025-10-27T05:16:57Z")

</div>

You should definitely not compute the Schur complement yourself.
