# Incorrect convergence rate for "Element\_P4" in 2d

**URL:** <https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400>\
**Category:** General Discussion\
**Created:** [December 21, 2021, 7:42pm UTC](https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400 "2021-12-21T19:42:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newhat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/newhat/32/618_2.png) [@Newhat](https://community.freefem.org/u/Newhat)\
**Post date:** [December 21, 2021, 7:42pm UTC](https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400/1 "2021-12-21T19:42:57Z")

</div>

```auto
load "Element_P3"
load "Element_P4"
int k = 1*2*2;
mesh Th = square(10*k, 10*k);
//plot(Th);
func Pk = P4;
fespace Vhc ( Th, Pk );
Vhc uc,ucX,ucY,fC,fCh,ucEX,err;
//--exact solution, partial derivatives and rhs----
ucEX = exp(x^2/4+y^2/4);
ucX = exp(x^2/4+y^2/4)*x/2;
ucY = exp(x^2/4+y^2/4)*y/2;
fC = exp(x^2/4+y^2/4)*(-x^2/4-y^2/4);
//------ get the matrice and right hand side ------
varf ahc(u,v) = int2d(Th)( dx(u)*dx(v)+dy(u)*dy(v) +u*v );
varf rhsC(unused,v) = int2d(Th)(fC*v)
                     +int1d(Th,1)( (N.x*ucX+N.y*ucY)*v )
                     +int1d(Th,2)( (N.x*ucX+N.y*ucY)*v )
                     +int1d(Th,3)( (N.x*ucX+N.y*ucY)*v )
                     +int1d(Th,4)( (N.x*ucX+N.y*ucY)*v ); 
//----------------solve the linear system----------
matrix Ahc;
Ahc = ahc(Vhc,Vhc);
set(Ahc, solver=CG, eps=1e-20);
fCh[] = rhsC(0,Vhc);
uc[] = Ahc^-1*fCh[];
//--------------- get the error -------------------
err[] = uc[]-ucEX[];
cout.scientific<<"Infinity error:"
<<max(abs(err[].min), abs(err[].max))<<endl;
real l2er;
l2er = ( int2d(Th)( (ucEX-uc)^2) );
cout.scientific<<"L2 error: "<<sqrt(l2er)<<endl;

```

**Question: in this example, I verified the L2 convergence rate for P3 element as k varies which is correct.**  
**However, the convergence rate for P4 element is incorrect. Am I wrong somewhere?**

Thanks a lot for your help.  
[P4Element.edp](https://community.freefem.org/uploads/short-url/cdIDD45q7XMYfMsEdVn2lbu1ExZ.edp) (1.1 KB)`Preformatted text`

---

<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:** [December 21, 2021, 8:53pm UTC](https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400/2 "2021-12-21T20:53:35Z")

</div>

You need to use an appropriate `qforder`, see [Quadrature formulae](https://doc.freefem.org/references/quadrature-formulae.html#qf9pt) or this similar topic [Default quadrature rule](https://community.freefem.org/t/default-quadrature-rule/415).

---

<div class="post-metadata">

**Author:** ![Newhat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/newhat/32/618_2.png) [@Newhat](https://community.freefem.org/u/Newhat)\
**Post date:** [December 21, 2021, 9:25pm UTC](https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400/3 "2021-12-21T21:25:18Z")

</div>

Thank you so much, Pierre.  
It works!

---

<div class="post-metadata">

**Author:** ![tea](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tea](https://community.freefem.org/u/tea)\
**Post date:** [October 21, 2024, 2:32pm UTC](https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400/4 "2024-10-21T14:32:57Z")

</div>

Dear Newhat,

may I ask, which qforder did you use?

---

<div class="post-metadata">

**Author:** ![Newhat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/newhat/32/618_2.png) [@Newhat](https://community.freefem.org/u/Newhat)\
**Post date:** [October 22, 2024, 2:18pm UTC](https://community.freefem.org/t/incorrect-convergence-rate-for-element-p4-in-2d/1400/5 "2024-10-22T14:18:49Z")

</div>

qforder=5, the quadrature formulae should have higher (at least not less) order than the element.
