Laplace equation on a disk solution

Define our boundary condition function.

f[θ_]=Piecewise[{{0,-Pi<θ<0},{100,0<θ<Pi}}]

Compute the coefficients:

fdotone=Integrate[f[θ],{θ,-Pi,Pi}]

a[0]=fdotone/2/Pi

fdotcos=Integrate[f[θ]Cos[n θ],{θ,-Pi,Pi}]

fdotcos=Simplify[fdotcos,Assumptions->Element[n,Integers]]

fdotsin=Integrate[f[θ]Sin[n θ],{θ,-Pi,Pi}]

fdotsin=Simplify[fdotsin,Assumptions->Element[n,Integers]]

sindotsin=Integrate[Sin[n θ]^2,{θ,-Pi,Pi}]

sindotsin=Simplify[sindotsin,Assumptions->Element[n,Integers]]

b[n_]=fdotsin/sindotsin

Table[b[n],{n,1,15}]

Now put together a partial sum of product solutions with these coefficients:

u[r_,θ_,nmax_]:=a[0]+Sum[b[n]r^n Sin[n θ],{n,1,nmax}]

We'll use RevolutionPlot3D to plot the surface graph.  Here's an example:

RevolutionPlot3D[r^3Sin[3θ]+r^4Sin[4 θ],{r,0,1},{θ,-Pi,Pi},PlotRange->All]

Using RevolutionPlot3D to plot our partial sum of product solutions gives

RevolutionPlot3D[u[r,θ,51],{r,0,1},{θ,0,2Pi},PlotRange->All]

RevolutionPlot3D[u[r,θ,51],{r,0,1},{θ,0,2Pi},PlotRange->All,MeshFunctions->{#3&}]

We can also look at θ=constant slices.

Plot[u[r,Pi/2,101],{r,0,1},PlotRange->All,AxesLabel->{r,u}]

This manipulation object lets us vary the angle of the slice.

Manipulate[Plot[u[r,θ,101],{r,0,1},PlotRange->{0,100},AxesLabel->{r,u}],{θ,-Pi,Pi}]

Contour plot (not done in class)

To get a contour plot, we need to convert to cartesian coordinates.  One step in this is using TrigExpand to reexpress trig functions of the form sin(nθ).  Here's an example:

TrigExpand[r^3Sin[3 θ]]

We can now follow up this expansion with application of a rule that transforms polar to cartesian coordinates.  Here's an example:

TrigExpand[r^3 Sin[3 θ]]/.{Sin[θ]->y/r,Cos[θ]->x/r}

We can put these steps into our expression for the partial sum of product solution.  Here's an example:

a[0]+
Sum[b[n]TrigExpand[r^n Sin[n θ]]/.{Sin[θ]->y/r,Cos[θ]->x/r},{n,1,3}]

Using these ideas, we build the following cartesian expression for our partial sum of product solutions:

ucart[x_,y_,nmax_]:=a[0]+
Sum[b[n]TrigExpand[r^n Sin[n θ]]/.{Sin[θ]->y/r,Cos[θ]->x/r},{n,1,nmax}]

ucart[x,y,7]

We can now use ContourPlot.  Here's a simple example:

ContourPlot[x+y,{x,0,1},{y,0,1}]

Here's a more relevant example:

ContourPlot[ TrigExpand[r Sin[θ]]/.{Sin[θ]->y/r,Cos[θ]->x/r},{x,-1,1},{y,-1,1},
RegionFunction->Function[{x,y},x^2+y^2<1],
Contours->Range[-1,1,0.2]]

In some cases, round-off causes funny labels to show up.  The next example uses Round to overcome this.

ContourPlot[ TrigExpand[r Sin[θ]]/.{Sin[θ]->y/r,Cos[θ]->x/r},{x,-1,1},{y,-1,1},
RegionFunction->Function[{x,y},x^2+y^2<1],
Contours->Round[Range[-1,1,0.2],0.01]]

Finally, we are ready to get a contour plot for our solution.

ContourPlot[ucart[x,y,15],{x,-1,1},{y,-1,1},
RegionFunction->Function[{x,y},x^2+y^2<1],
Contours->Range[0,100,10]]

Constructing a contour plot requires evaluating the function at a lot of points.  For our function, this is very time consuming largely because we've defined ucart using a delayed evaluation so the sum is being recreated repeatedly.  If we "lock in" a value for nmax, we can some efficiency.  Here's an example with nmax having the value 21:

ucart21=Simplify[ucart[x,y,21]]

The corresponding contour plot is produced much faster:

ContourPlot[ucart21,{x,-1,1},{y,-1,1},
RegionFunction->Function[{x,y},x^2+y^2<1],
Contours->Range[0,100,10],
ContourLabels->All]

Laplace equation on a disk solution--second boundary condition

Now we define our boundary condition function.

f[θ_]=100/2/Pi θ

Compute the coefficients:

fdotone=Integrate[f[θ],{θ,-Pi,Pi}]

a[0]=fdotone/2/Pi

fdotcos=Integrate[f[θ]Cos[n θ],{θ,-Pi,Pi}]

fdotsin=Integrate[f[θ]Sin[n θ],{θ,-Pi,Pi}]

fdotsin=Simplify[fdotsin,Assumptions->Element[n,Integers]]

sindotsin=Integrate[Sin[n θ]^2,{θ,-Pi,Pi}]

sindotsin=Simplify[sindotsin,Assumptions->Element[n,Integers]]

b[n_]=fdotsin/sindotsin

Table[b[n],{n,1,15}]

Now put together a partial sum of product solutions with these coefficients:

u[r_,θ_,nmax_]:=a[0]+Sum[b[n]r^n Sin[n θ],{n,1,nmax}]

Using RevolutionPlot3D to plot our partial sum of product solutions gives

RevolutionPlot3D[u[r,θ,51],{r,0,1},{θ,0,2Pi},PlotRange->All]

RevolutionPlot3D[u[r,θ,51],{r,0,1},{θ,0,2Pi},PlotRange->All,MeshFunctions->{#3&}]

Using these ideas, we build the following cartesian expression for our partial sum of product solutions:

ucart[x_,y_,nmax_]:=a[0]+
Sum[b[n]TrigExpand[r^n Sin[n θ]]/.{Sin[θ]->y/r,Cos[θ]->x/r},{n,1,nmax}]

ucart[x,y,7]

Here's a more relevant example:

Finally, we are ready to get a contour plot for our solution.

Constructing a contour plot requires evaluating the function at a lot of points.  For our function, this is very time consuming largely because we've defined ucart using a delayed evaluation so the sum is being recreated repeatedly.  If we "lock in" a value for nmax, we can some efficiency.  Here's an example with nmax having the value 21:

ucart21=Simplify[ucart[x,y,21]]

The corresponding contour plot is produced much faster:

ContourPlot[ucart21,{x,-1,1},{y,-1,1},
RegionFunction->Function[{x,y},x^2+y^2<1],
Contours->Range[0,100,10],
ContourLabels->All]