# 2D Laplace equation using NDSolve and mixed boundary conditions

I would like to solve the laplace-equation in 2 dimensions, using mixed boundary conditions. The code I used is:

NDSolve[
{D[u[x, z], x, x] == -D[u[x, z], z, z],u[x, 10] == 0,
(D[u[x, z], z] /. z -> 10) == 0,u[x, 0] == SquareWave[x]},
u, {x, 0, 10}, {z, 0, 10}]


The error messages I get are:

CoefficientArrays::poly: (u^(0,1))[x,10] is not a polynomial.

NDSolve::fembdnl: The dependent variable in (u^(0,1))[x,10]==0
in the boundary condition DirichletCondition[(u^(0,1))[x,10]==0,z==10.]
needs to be linear.


I don't know what's the problem, can you help me figure out this error messages?

Best regards

Thorsten

• Your boundary condition is wrong. (You set 3 boundary conditions in z direction and 0 boundary condition in x direction.) – xzczd Oct 21 '16 at 14:04

You must write u[x,z] instead of u in NDSolve. Then the problem can be numerically solved.

However, as xzczd pointed out in a coment, the boundary conditions are not correct. With three b.c. in z-direction an None in x-direction the problem is ill-defined.

Nevertheless there is a numerical "solution", and due to numerical inaccuracy the violation of the second b.c. (the derivative) is not obvious.

Here is the numerical solution:

\$Version

(* Out= "10.1.0  for Microsoft Windows (64-bit) (March 24, 2015)" *)

uu[x_, z_] =
u[x, z] /.
NDSolve[{D[u[x, z], x, x] == -D[u[x, z], z, z],
u[x, 10] == 0, (D[u[x, z], z] /. z -> 10) == 0,
u[x, 0] == SquareWave[x]}, u[x, z], {x, 0, 10}, {z, 0, 10}][]

(* Out= InterpolatingFunction[{{0., 10.}, {0., 10.}}, <>][x, z] *)

Plot3D[uu[x, z], {x, 0, 10}, {z, 0, 10},
ViewPoint -> {\[Pi], \[Pi]/2, 2}, AxesLabel -> {x, z, u}] • Well... but how can one set 3 b.c. for one direction when solving Laplace equation? – xzczd Oct 21 '16 at 15:25
• @xzczd Good question. You are right. In my opinion it is a numerical effect that you are allowed to gives 3 b.c. Try varying the derivative (D[u[x, z], z] /. z -> 10) == d. You can go as high as d = 20 without altering the picture. This b.c. is by no means matched. So one should be careful appreciating nice pictures. – Dr. Wolfgang Hintze Oct 21 '16 at 16:12
• @xzczd Please see the updated version of my solution. – Dr. Wolfgang Hintze Oct 21 '16 at 16:20
• I even guess in v10.1 that b.c. is simply ignored. Just tested on Cloud, though using 3 b.c. will cause failure in v11, if the condition D[u[x, z], z] /. z -> 10) == 0 is taken away, a plot that just looks the same as the above one will be generated. – xzczd Oct 22 '16 at 3:03