# About stiffness martix

**URL:** https://community.freefem.org/t/about-stiffness-martix/2022
**Category:** General Discussion
**Created:** [September 24, 2022, 5:52am UTC](https://community.freefem.org/t/about-stiffness-martix/2022 "2022-09-24T05:52:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Yangshen](https://avatars.discourse-cdn.com/v4/letter/y/838e76/32.png) [@Yangshen](https://community.freefem.org/u/Yangshen)
#### Post date: [September 24, 2022, 5:52am UTC](https://community.freefem.org/t/about-stiffness-martix/2022/1 "2022-09-24T05:52:01Z")

</div>

Dear all,  
I used the following code to extract the stiffness matrix of the grid as shown in the figure, with the left boundary fixed.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/9/9265aafdb2e17d2211db740ee6d53ce652c45f89.png)  
The structure is relatively simple. The stiffness matrix can be pushed manually. It should be an 8 \* 8 matrix, but only 56 elements can be calculated by FreeFEM. See the figure below.  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/ebcb4d6312d98f29cc0bab9e43d7cf1d4c4a3b22.png)  
I guess it’s because some 0 elements are omitted, isn’t it?

Here is my code.  
//Parameters  
real Rho = 8000.; //Density  
real E =210.; //Young modulus  
real Nu = 0.27; //Poisson ratio

real Gravity = -9.81; //Gravity

mesh Th = square(1,1);

//Fespace  
func Pk = P1;  
fespace Uh(Th, [Pk, Pk]);  
Uh [ux, uy];

//Macro  
real sqrt2 = sqrt(2.);  
macro Epsilon(ux, uy) [dx(ux), dy(uy), (dy(ux)+dx(uy))/sqrt2] //  
macro Divergence(ux, uy) (dx(ux) + dy(uy)) //

//Problem  
real Mu = E/(2._(1.+Nu));  
real Lambda = E_Nu/((1.+ Nu)\*(1.-2.\*Nu));

varf vElasticity ([ux,uy], [vx, vy])  
= int2d(Th)(  
Lambda \* Divergence(vx, vy) \* Divergence(ux, uy)  
+ 2. \* Mu \* (  
Epsilon(vx, vy)’ \* Epsilon(ux, uy)  
)  
)  
+ int2d(Th)(  
Rho \* Gravity \* vy  
)  
+ on(4, uy=0,ux=0)  
;

matrix Elasticity = vElasticity(Uh, Uh, solver=sparsesolver);

//Movemesh  
Th = movemesh(Th, [x+ux, y+uy]);  
[ux, uy] = [ux, uy];

//Plot  
plot(Th,wait = 1);  
cout \<\<" u = "\<\< Elasticity \<\< endl;

---

<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: [September 24, 2022, 5:56am UTC](https://community.freefem.org/t/about-stiffness-martix/2022/2 "2022-09-24T05:56:40Z")

</div>

Yes, FreeFEM uses sparse matrices by default, so (most) zero coefficients are not stored.
