# Finding a scalar field whose gradient is a given conservative vector field

I'm studying for a course in electromagnetism, and I've been given an electric field for which I need to find the associated scalar potential. I was going to originally post this in the physics section but I think my problems are more calculus related. The field is the field generated by a sphere of radius $R$ with constant charge density $\rho$ throughout its volume, so that the total charge $Q=\dfrac{4\pi r^3 \rho}{3}$contained in the sphere is constant.

The electric field is given by $\vec{E}_{\text{in}}(\vec{r})=\dfrac{Q}{4\pi \epsilon_0 R^3}r$ and $\vec{E}_{\text{out}}(\vec{r})=\dfrac{Q}{4\pi \epsilon_0 r^2}$, where the former is valid for $r\leq R$ and the latter for $r\geq R$. This I've calculated before and I do not have trouble with. The scalar potential $\phi(\vec{r})$ is defined by $\vec{E}=-\vec{\nabla}\phi$. The provided solutions to the problem are hand written but I'll type them here using the exact same notation:

$\phi_{\text{in}}=-\int \vec{E}_{\text{in}}d\vec{r}=-\dfrac{Qr^2}{8\pi \epsilon_0 R^3} + C_1$

$\phi_{\text{out}}=-\int \vec{E}_{\text{out}}d\vec{r}=\dfrac{Q}{4\pi \epsilon_0 r} +C_2$

This is literally all the information I've been given. I really don't know what these integrals are, nor how they follow from the above equation. I can see that the result of the first integral for example is just the indefinite integral $-\int \dfrac{Q}{4\pi \epsilon_0 R^3}r dr$ but I can't see how this stage was reached.

Any clarification would be much appreciated!

• en.m.wikipedia.org/wiki/Gradient_theorem – rajb245 Jun 25 '14 at 22:21
• You have $\mathbf{E}_{\mathrm{in}} = Qr/(4\pi\epsilon_0 R^3)$. But $\mathbf{E}_{\mathrm{in}}$ is a vector and the RHS of that equation is a scalar. You need a direction for $\mathbf{E}_{\mathrm{in}}$ (and the same applies to $\mathbf{E}_{\mathrm{out}}$). – eyeballfrog Jan 9 '17 at 5:05
• The OP should express anew his interest in an answer to his problem. Otherwise this question can be deleted, and should no longer be bumped to the main page every two weeks. – Christian Blatter Nov 27 '17 at 18:46
• $\vec{r}\cdot\mathrm{d}\vec{r} = r\,\mathrm{d}r$ – Felix Marin May 12 '18 at 16:44

The integrals are over the surface $S$ of the sphere (at radius $R$). The confusion might be because you overlooked a $\cdot$. The integrand is the dot product of $\vec{E}$ with the unit normal to the surface, which your professor has written as $d\vec{r}$ but wouild more commonly be written as $dS$. The integral can be read in spherical coordinates as $$\int_S E_r(R, \theta, \phi) r\,d\theta\,d\phi$$ and the $\vec{E}\cdot \vec{r}$ is just expressing that you need to take the $r$ component of the field.
• Thanks for the reply! Yeah the dot wasn't written in the solutions but I assumed that that's what my professor meant. I don't understand why this surface integral gives the potential though. Also, I'm not sure what you mean by the $r$ component - is that $E_r$? I don't know what $E_r$ is if I'm honest! – James Machin Jun 27 '14 at 0:21
$\newcommand{\bbx}{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}{\displaystyle{#1}} \newcommand{\expo}{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}{\mathcal{#1}} \newcommand{\mrm}{\mathrm{#1}} \newcommand{\pars}{\left(\,{#1}\,\right)} \newcommand{\partiald}[]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}{\left\vert\,{#1}\,\right\vert}$ \begin{align} \Phi\pars{\vec{r}} & = -\int_{\vec{a}}^{\vec{r}}\vec{\mrm{E}}\pars{\vec{s}}\cdot\dd\vec{s} + \Phi\pars{\vec{a}} = \overbrace{\int_{\vec{a}}^{\vec{r}}{Q \over 4\pi\epsilon_{0}s^{2}}\,{\vec{s} \over s}\cdot\dd\vec{s}}^{\ds{% \left\{\begin{array}{l} \mbox{Note that}\ \\ \ds{\vec{s}\cdot\dd\vec{s} = {1 \over 2}\,\dd\pars{\vec{s}\cdot\vec{s}}} \\ = \ds{{1 \over 2}\,\dd\pars{s^{2}} = \color{red}{s\,\dd s}} \end{array}\right.}}\ +\ \Phi\pars{\vec{a}} \\[5mm] & = -\,{Q \over 4\pi\epsilon_{0}}\int_{a}^{r}{\dd s \over s^{2}} + \Phi\pars{\vec{a}} = {Q \over 4\pi\epsilon_{0}}\pars{{1 \over r} - {1 \over a}} + \Phi\pars{\vec{a}} \end{align}
Set $\ds{\Phi\pars{\vec{a}} = 0}$ as $\ds{a \to \infty}$ such that $\bbx{\ds{\Phi\pars{\vec{r}} = {Q \over 4\pi\epsilon_{0}r}}}$.
• -this is the potential only for $r \geq R$, correct? Its gradient does not give the electric field $\vec{E}_{in}$ for $r \leq R$. – splitcomplexes Nov 2 '18 at 9:02
What the OP has given as the electric fields inside and outside the sphere are only the magnitudes of these fields, as has been emphasized in other comments and answers. I suspect that those expressions were derived using Gauss' Law, which relied on spherical symmetry to assume two things: (i) that the field at a point with position vector $$\vec{r}$$, a distance $$r = |\vec{r}|$$ from the center of the sphere, depended only on this distance, and (ii) that the field was directed radially outward from the center of the sphere along the unit vector $$\hat{r} = \vec{r}/r$$. So the electric field vector is a piecewise continuous function of the radial coordinate $$r$$ alone, with direction $$\hat{r}$$, given by \begin{align}\vec{E}(r) \,=\, \begin{cases}~~\vec{E}_{in}(r) = \dfrac{q}{R^3}\,r\,\hat{r}, ~~~ r \leq R, \\ \\~~ \vec{E}_{out}(r) = \dfrac{q}{r^2}\,\hat{r}, ~~~ r \geq R, \end{cases}\end{align} where I am writing $$q = \dfrac{Q}{4\pi\epsilon_0}$$ for convenience. Since $$\vec{E}(r)= -\nabla \phi(r)$$ depends only on the radial coordinate $$r$$, it reduces to $$\vec{E}(r) = -\dfrac{d\phi}{dr}(r)\,\hat{r}.$$ The negative derivative of the scalar function $$\phi(r)$$ with respect to $$r$$ thus gives the radial (and only) component of $$\vec{E}$$, so from the piecewise expressions for the electric field we find the piecewise expressions for the derivative of $$\phi$$: \begin{align}-\dfrac{d\phi}{dr} = \begin{cases}~~\dfrac{q}{R^3}\,r, ~~~ r \leq R, \\ \\~~ \dfrac{q}{r^2}, ~~~ r \geq R, \end{cases}\end{align} The indefinite integral of each side in the two cases gives $$\phi(r) = -\int\dfrac{q}{R^3}\,r\,dr = - \dfrac{q}{R^3}\dfrac{r^2}{2} + C_1, ~~~~r \leq R,$$ and $$\phi(r) = -\int\dfrac{q}{r^2}\,dr = \dfrac{q}{r} + C_2, ~~~~r \geq R.$$ In the second expression with $$r \geq R$$, in order for the potential to vanish as $$r \to \infty$$, we must set the integration constant $$C_2 = 0$$, hence $$\phi(r) = \dfrac{q}{r}, ~~~~r \geq R.$$ In order for the potential to be continuous at $$r = R$$, the potentials must be equal at the boundary: $$-\dfrac{q}{R^3}\dfrac{R^2}{2} + C_1 = \dfrac{q}{R},$$ from which we find $$C_1 = \dfrac{3q}{2R}.$$ The scalar potential is thus given by the piecewise continuous function \begin{align}\phi(r) \,=\, \begin{cases}~ -\dfrac{q}{R^3}\dfrac{r^2}{2} + \dfrac{3q}{2R}, ~~~r \leq R,\\ \\~~ \dfrac{q}{r}, ~~~r \geq R.\end{cases}\end{align} In terms of $$q = Q/4\pi\epsilon_0$$, these are \begin{align}\phi(r) \,=\, \begin{cases}~~-\dfrac{Q}{8\pi\epsilon_0 R^3}\,r^2 + \dfrac{3Q}{8\pi\epsilon_0 R}, ~~~r \leq R,\\ \\ ~~\dfrac{Q}{4\pi\epsilon_0 r}, ~~~r \geq R.\end{cases}\end{align}