# How to get the sub-matrix of A?

#1

Dear all,

I am new to FreeFEM++ and I want to ask a simple question.
If I have already obtained a matrix by matrix A = va(Vh, Vh);, how to get the sub-matrix of A? For example in Matlab, you can simply write A(1:i, 1:j).

wys

(Simon Garnotel) #2

I do not know if a simple technique exists for sparse matrix, but you can use the [I, J, C] decomposition (see here) to manually modify your matrix

(Simon Garnotel) #3

Update: It is possible using indexes.

A working example:

``````mesh Th = square(10, 10);
fespace Uh(Th, P1);
varf vL (u, uh)
= int2d(Th)(
u * uh
)
+ on(1, 2, u=0)
;
matrix L = vL(Uh, Uh);

int imin = 10;
int imax = 50;
int jmin = 15;
int jmax = 45;
int[int] I(imax-imin);
for (int i = 0; i < I.n; i++)
I[i] = imin + i;
int[int] J(jmax-jmin);
for (int j = 0; j < J.n; j++)
J[j] = jmin + j;

matrix L2;
L2 = L(I, J);
``````
#4

Thank you very much!