Solve and illustrate the Dirichlet problem $u_{xx}+u_{yy}=0$ on the square with boundary conditions
$$
\begin{array}{ll}
u(x,0) = 4x(1-x) && u(x,1) = -4x(1-x) \\
u(0,y) = 0 && u(1,y) = 0.
\end{array}
$$
Laplace on the square with NDSolve
For this problem, I will use the "NDSolveValue" Mathematica command to illustrate the solutions to Laplace's equation. I'm assuming that we are considering the unit square. Setting up the fully specified PDE as given,
Clear[u];
u = NDSolveValue[{
D[u[x, y], x, x] + D[u[x, y], y, y] == 0,
u[x, 0] == 4 x (1 - x), u[1, y] == 0,
u[x, 1] == -4 x (1 - x), u[0, y] == 0},
u, {x, 0, 1}, {y, 0, 1}];
describes the Dirichlet problem.
Next, I will plot the solution using the Plot3D command, like so:
Plot3D[u[x, y], {x, 0, 1}, {y, 0, 1},
PlotRange -> All, PlotPoints -> 50,
ColorFunction -> "TemperatureMap",
MeshFunctions -> {Function[{x, y, z}, z]}]
This produces the following plot:
Also, I created a contour plot with the following code.
ContourPlot[u[x, y], {x, 0, 1}, {y, 0, 1},
PlotRange -> All, PlotPoints -> 50,
ColorFunction -> "TemperatureMap"]
This shows the y-boundaries ($x=0$ and $x=1$) fixed at zero, while the x-boundaries ($y=0$ and $y=1$) are set to a quadratic condition.
I would love to embed Mathematica code within my posts, but I can't figure it out. If anyone knows, let me know and I will edit my post!
When you're posting a reply, the little bar up top, there's something that looks like a quotation mark, hit that. It's a blockquote and it'll let you post your mathematica code. Either that or you can hit the space bar four times on a new line and type/paste what you need to. For example:
Plot[x^2, {x, -2, 2}]
Hope that helps. Also, your answer looks good! :$\small)$
Well, that's very cool! I edited your post so that you could see how to include code. Like qkahn said, it's just a matter of indentation. There's one code block left, if you want to try.
Thanks, @Mark and @qkhan! I've updated my original post.