I am trying to get some code working for the 1D Poisson equation using the textbook: Nodal Discontinuous Galerkin Methods Algorithms, Analysis, and Applications.

I use the following formulation (for a homogeneous case):

enter image description here

In order to account for inhomogeneous cases, the textbook proposes the following:

enter image description here

where $\mathcal A$ is given from the homogeneous case. When I attempt to implement the added term on the right-hand side of the equation above, I obtain the following response, which seems to almost respond correctly; however, the first and last terms deviate greatly from their specified b.c:

enter image description here

I implement the extra rhs term with the following code:

e = zeros((basisdegree+1),numelements);
enp = e; enp(end) = 1; e1 = e; e1(1) = 1;
extraterm = Dr*(enp*b - e1*a);

Where e is just a vector the size of the solution u, with 1 located in the first and last element. Dr is the same as in the homogeneous equations which are $\mathcal{M}^{-1} \mathcal{S}$.


1 Answer 1


You did everything right but forgot that the way you impose boundary values leads to a solution that has zero boundary values (when applied strongly) and for which you have to set the first and last degree of freedom to their correct value after solving the linear system. The solution will then be correct/as expected.

  • $\begingroup$ Hi Wolfgang, thanks for the answer. When I hardset the values after solving the equation the graph looks good. The only issue I run into now is that when I use higher order basis functions the points around the start and end of the graph I attached in the initial question (all the points with different values on the same node) begin oscillating largely. Is this an issue with how I have enforced my boundary conditions? $\endgroup$
    – Mitchell
    Apr 20, 2018 at 6:11
  • $\begingroup$ I also realised that I was using Dr (inv(M)*S) instead of S*inv(M) which now also throws the graph out of alignment with the BC's however still maintains the correct(ish) form. $\endgroup$
    – Mitchell
    Apr 20, 2018 at 7:11
  • $\begingroup$ I have a hard time understanding the formulation you use, but basically you subtract something from the solution that has the correct boundary values and shove it over to the right hand side. Then you solve for the "rest", but the complete solution is this "rest" plus whatever you subtracted. You'll have to think about what that is exactly. $\endgroup$ Apr 20, 2018 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.