2D Laplace Equation

Specify the Laplace equation

In[]:=
eqn=Laplacian[u[x,y],{x,y}]==0
Out[]=
(0,2)
u
[x,y]+
(2,0)
u
[x,y]0

Specify the Region

In[]:=
width=48;​​height=12;
In[]:=
Ω=Rectangle[{0,0},{width,height}]
Out[]=
Rectangle[{0,0},{48,12}]
In[]:=
Ω
1
=Polygon[{{0,0},{43,0},{23,10},{20,10}}];

Specify the Boundary Conditions

In[]:=
dcond1=DirichletConditionu[x,height]==22,x<=
width
3

Out[]=
DirichletCondition[u[x,12]22,x≤16]
In[]:=
dcond2=DirichletConditionu[x,height]==18,x>
2width
3

Out[]=
DirichletCondition[u[x,12]18,x>32]
In[]:=
dcond3=DirichletCondition[u[x,0]==0,True]
Out[]=
DirichletCondition[u[x,0]0,True]

Solve the Dirichlet problem

In[]:=
solution=NDSolveValue
2
∇
{x,y}
u[x,y]==NeumannValue[0,y==0]+NeumannValue[0,x==0]+NeumannValue[0,x==width]+NeumannValue0,y==height&&
width
3
<x<
2width
3
,{dcond1,dcond2},u,{x,y}∈Ω
Out[]=
InterpolatingFunction
Domain: {{0.,48.},{0.,12.}}
Output: scalar


Visualize the Solution

In[]:=
ContourPlotsolution[x,y],{x,y}∈Ω,​​AspectRatio
1
3
,PlotRange->All,AxesLabel{"x","y"}
Out[]=

Vector Field

In[]:=
v=Grad[-solution[x,y],{x,y}]
Out[]=
-InterpolatingFunction
Domain: {{0.,48.},{0.,12.}}
Output: scalar
[x,y],-InterpolatingFunction
Domain: {{0.,48.},{0.,12.}}
Output: scalar
[x,y]
In[]:=
VectorPlotv,{x,y}∈Ω,AspectRatio
1
3
,PlotRange->All,AxesLabel{"x","y"},PlotLegendsAutomatic
In[]:=
Plot3Dsolution[x,y],{x,y}∈Ω,​​AspectRatio
2
3
,PlotRange->All,AxesLabel{"x","y","u(x,y)"},PlotTheme"Business"
Out[]=