# Let the exact solution is unknown for the Poisson equation. How to compute the L2 error estimate u\_h - u\_h/2

**URL:** <https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653>\
**Category:** General Discussion\
**Created:** [August 13, 2023, 12:01pm UTC](https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653 "2023-08-13T12:01:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [August 13, 2023, 12:01pm UTC](https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653/1 "2023-08-13T12:01:13Z")

</div>

cout \<\< endl;  
cout \<\< “convergence:” \<\< endl;  
real r=1;real L2error;  
func uhold=0;  
for ( int log2 = 4; log2 \<= 5; log2++ )  
{  
int m = pow ( 2.0, log2 );  
border C(t=0, 2\*pi){x=cos(t); y=sin(t);}  
mesh Th = buildmesh(C(m));  
func f= 1;  
func u=(1-x^2-y^2)/4;  
fespace Vh(Th, P1);  
Vh uh, v,uhold;// Define u and v as piecewise-P1 continuous functions  
solve Poisson(uh, v, solver=LU)  
= int2d(Th)(dx(uh)\*dx(v)+ dy(uh)_dy(v)) - int2d(Th)(f_v)+ on(C, uh=0);  
if(4==log2)  
{  
Vh uhold=uh;  
plot(uhold,dim=3,value=true,fill=true,ShowAxes=0,ColorScheme =1);  
}  
if(4\<log2)  
{  
plot(uhold,dim=3,value=true,fill=true,ShowAxes=0,ColorScheme =1);  
plot(uh,dim=3,value=true,fill=true,ShowAxes=0,ColorScheme =1);  
L2error=sqrt(int2d(Th)((uh-uhold)^2));  
cout \<\< " L2 = " \<\< L2error \<\< endl;  
}  
}  
cout \<\< “\n”;  
cout \<\< “convergence:\n”;  
cout \<\< " Normal end of execution.\n";

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [August 13, 2023, 8:22pm UTC](https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653/2 "2023-08-13T20:22:20Z")

</div>

this the problem,

```auto
L2error=sqrt(int2d(Th)((uh-u)^2));

```

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [August 13, 2023, 9:33pm UTC](https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653/3 "2023-08-13T21:33:05Z")

</div>

The have corrected you script

the main issue is the mesh change and your want to compare 2 solution on different meshes;  
:so the mesh must be defined outside of the loop

[poisson.edp](https://community.freefem.org/uploads/short-url/kznzJ7hlpZwT8HwzgOgeehLX2qh.edp) (952 Bytes)

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [August 13, 2023, 11:02pm UTC](https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653/4 "2023-08-13T23:02:14Z")

</div>

Thanks, I thought he meant " known " lol.

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [August 14, 2023, 12:41pm UTC](https://community.freefem.org/t/let-the-exact-solution-is-unknown-for-the-poisson-equation-how-to-compute-the-l2-error-estimate-u-h-u-h-2/2653/5 "2023-08-14T12:41:12Z")

</div>

Thanks Sir. I got it.
