Wolfram Language

Partial Differential Equations

Solve a Dirichlet Problem for the Laplace Equation

Specify the Laplace equation in 2D.

In[1]:=
Click for copyable input
leqn = Laplacian[u[x, y], {x, y}] == 0;

Prescribe a Dirichlet condition for the equation in a rectangle.

In[2]:=
Click for copyable input
\[CapitalOmega] = Rectangle[{0, 0}, {1, 2}];
In[3]:=
Click for copyable input
dcond = DirichletCondition[ u[x, y] == Piecewise[{{UnitTriangle[2 x - 1], y == 0 || y == 2}}, 0], True];

Solve the Dirichlet problem.

In[4]:=
Click for copyable input
sol = DSolveValue[{leqn, dcond}, u[x, y], {x, y} \[Element] \[CapitalOmega]] // FullSimplify
Out[4]=

Extract the first 300 terms from the Inactive sum.

In[5]:=
Click for copyable input
asol = sol /. {\[Infinity] -> 300} // Activate;

Visualize the solution on the rectangle.

In[6]:=
Click for copyable input
Plot3D[asol // Evaluate, {x, y} \[Element] \[CapitalOmega], PlotRange -> All, PlotTheme -> "Business"]
Out[6]=

Related Examples

de es fr ja ko pt-br ru zh