Variational Solution to the Dirichlet BVP for Possion's Equation in Cylindrical Coordinates given in Chapter 1 of Jackson.

Variational Approximation

We want to solve the Poisson equation (▽^2)ϕ = -g[r] in cylindrical coordinates subject to the Dirichlet boundary condition ϕ[1] = 0.  As a first step, we set up a variational function ϕ[r,a,b,c] that has a polynomial dependence on r and vanishes at r=1.  Since the electric field must vanish at r=0 for a cylindrically symmetric charge distribution (by Gauss's law), we also must require d(ϕ/dr)=0 at r=0. To achieve this, we omit the linear term in the polynomial. Here is our ansatz for the potential.

ϕ[r_] =  
      a r^2  + b r^3  +  c r^4  - (a + b + c)

As a second step, we evaluate the gradient term that occurs in the action integral

dϕ[x_]  =   D[ϕ[x], x]

Now, we form the first part of the "action" integral

kin =  Integrate[r dϕ[r]^2/2, {r, 0, 1}]

Next, we form the second term in the action integral. In the equation below, we adopt the notation
 en = ∫g[
            r] ((r^n) - 1) r dr.

pot  =  a e2  +  b e3  +  c e4

Here is the complete action integral

S  =  kin - pot

Now find the derivatives of S with respect to a, b, and c.

da  =  D[S, a]

db  =  D[S, b]

dc  =  D[S, c]

Now, we solve the system of equations dS/da =0, dS/db=0, dS/dc=0.

Solve[{da == 0, db == 0, dc == 0}, {a, b, c}] // 
      First

a  =  a /.  %

b  =  b /.  %%

c   =  c  /.  %%%

Now, lets examine the solution with a specific choice for the inhomogeneous term g[r]

g[r_] =  -5 (1 - r)  +  10^4 r^5 (1 - r)^5

With this choice, we can evaluate e2, e3, e4 explicitly

e2 =  Integrate[(r^2 - 1) r g[r], {r, 0, 1}]

e3 =  Integrate[(r^3 - 1) r g[r], {r, 0, 1}]

e4 =  Integrate[(r^4 - 1) r g[r], {r, 0, 1}]

What is the final result for ϕ[r]?

ϕ[r]

Let's take a look!  In the figure below, ϕ[r] is in red and g[r]/20 is in cyan.

Plot[{ϕ[r], g[r]/20}, {r, 0, 1}, PlotRange -> {-0.3, 0.7}, 
      PlotStyle ->  {{Thickness[0.007], 
            RGBColor[1, 0, 0]}, {Thickness[0.01], 
            RGBColor[0, 1, 1]}}]

Exact Answer

In this case, we can easily determine the exact answer ψ[r] by solving the radial dfferential equation
 (1/r)(d/dr)r d(ψ/dr)= -g[r] 
 subject to boundary conditions d(ψ/dr)[0] = 0 and ψ[1] = 0.  A first integral gives  ψ' = d(ψ/dr)

ψ'[
        r_]  =  -Expand[Integrate[x g[x], {x, 0, r}]/r]

A second integral gives ψ[r]

ψ[r_]  =  Integrate[ψ'[x], {x, 1, r}]

Are the boundary conditions satisfied?

ψ[1]

D[ψ[r], r]  /.  r ->  0

Let's compare the exact solution (black) with the vatiational approximation (red)

Plot[{ψ[r], ϕ[r], g[r]/20}, {r, 0, 1}, 
      PlotRange -> {-0.3, 0.7}, 
      PlotStyle ->  {{Thickness[0.007], 
            RGBColor[0, 0, 0]}, {Thickness[0.007], 
            RGBColor[1, 0, 0]}, {Thickness[0.01], 
            RGBColor[0, 1, 1]}}]

Let's now take a look at the difference between the ϕ[r] and ψ[r]

Plot[(ϕ[r] - ψ[r]), {r, 0, 1}, 
      PlotRange ->  {-0.015, 0.015}, 
      PlotStyle -> {Thickness[0.01], Hue[0.94]}]

Clear["`*"]