I have the following PDE: $$ \frac{\partial }{\partial x}\left(G_x \left(\frac{\partial \phi (x,y)}{\partial x}-y\right)\right)+\frac{\partial }{\partial y}\left(G_y \left(\frac{\partial \phi (x,y)}{\partial y}+x\right)\right)=0 $$ with BCs $\frac{\partial \phi (x,y)}{\partial x}-y=0$ at $x=\pm a$ and $\frac{\partial \phi (x,y)}{\partial y}+x=0$ at $y=\pm b$, $G_x$ and $G_y$ are constants.

After a lot of work and help from this community I managed to get an analytical solution. Now I want to confirm this solution using NDSolve so I typed the following code:

(*Main equation*)
(*Values for numerical solution*)


but I get the message

NDSolve::fembdnl: The dependent variable in -y+(\[Phi]^(1,0))[-0.0025,y]==0 in the boundary condition DirichletCondition[-y+(\[Phi]^(1,0))[-0.0025,y]==0,x==-0.0025] needs to be linear.

I thought that all equations can have a numerical solution but are not guaranteed an analytical one so I'm sure I'm making a mistake but I can't see where.

Side note: here is the analytical solution $$ \phi (x,y)=x y-\frac{32 \sqrt{G_y} (-1)^n \sin \left(\frac{1}{2} \pi (2 n+1) x\right) \text{sech}\left(\frac{\pi b \sqrt{G_x} (2 n+1)}{2 \sqrt{G_x}}\right) \sinh \left(\frac{\pi \sqrt{G_x} (2 n+1) y}{2 \sqrt{G_y}}\right)}{\pi ^3 \sqrt{G_x} (2 n+1)^3} $$ where $n=0,1,2,3,...$.


1 Answer 1


Something like this should get you started:

bcs = DirichletCondition[\[Phi][x, y] == analyticalSolution[x, y], 

sol = NDSolveValue[{Inactive[
      Div][{{Gx, 0}, {0, Gy}}.Inactive[Grad][\[Phi][x, y], {x, 
         y}] + {{-Gx y, Gy x}}, {x, y}] == 0(*,bcs*)}, \[Phi], {x, -a,
    a}, {y, -b, b}]

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.