# Integrating a dot product gives wrong sign for work done [duplicate]

This question already has an answer here:

Consider a point mass which creates a gravitational field. The gravitational force pulls a 'test mass' towards the point mass. Since the displacement and gravitational force are in the same direction, the work done by the gravity is positive. I would like to show this mathematically, but my answer comes out negative:

I think the source of this error is how I deal with the displacement (highlighted). The displacement is in the negative direction (towards the point mass), but because you take its magnitude when doing the dot product, I didn't think its direction mattered. I therefore proceeded to swap $ds$ for $dr$ (not really knowing what I was doing, but it seemed to make sense, because $s$ and $r$ are both displacements, albeit in opposite directions).

How should I correctly integrate this dot product to get the right sign of work done?

## marked as duplicate by Kyle Kanos, John Rennie, stafusa, Jon Custer, YashasDec 6 '17 at 13:31

• Analogous electrostatic problem: physics.stackexchange.com/q/17938/2451 and links therein. – Qmechanic Dec 3 '17 at 12:46
• Duplicate physics.stackexchange.com/q/360281 – Farcher Dec 3 '17 at 13:07
• You worry far too much about these signs by overthinking things. Look at it like this: The displacement vector $\vec{ds}$ and the force vector $\vec{F}$ clearly point in the SAME direction, so $dW=\vec{F}.\vec{ds}>0$. See also here: physics.stackexchange.com/q/372118 – Gert Dec 3 '17 at 14:30
• The problem is that $|d \vec{s}|$ is supposed to be positive, but $dr$ is negative because $r_1 > r_2$. So $-dr$ should be substituted for $|d \vec{s}|$. – Peter Shor Dec 3 '17 at 14:34
• Don't paste pictures of math, but rather type in MathJax. – ja72 Dec 3 '17 at 17:49

Where did you go wrong?

According to you the work done must be positive because you are evaluating $|\vec F| \cos 0 |d\vec s|$ and all three terms in that expression are positive.

The magnitude of $\vec F$, $|\vec F|$, must be equal to the positive quantity $\dfrac{GMm}{r^2}$ as $r>0$ so $\vec F = \dfrac{GMm}{r^2} (- \hat r)$

$d\vec s = |d\vec s| (-\hat r) = ds (-\hat r)$

This gives $\vec F \cdot d\vec s = \dfrac{GMm}{r^2} (-\hat r) \cdot ds (-\hat r) = \dfrac{GMm}{r^2}\, ds$ with $ds$ positive as it is the magnitude of $d\vec s$.

So to use this expression you must have $ds$ positive ie any integration must be one where $r$ increases unless you substitute $(-dr)$ for $ds$.

If you deal with components rather than magnitudes you do not run into the same problem.

Let us start with $\vec F \cdot d\vec s$ which in your case is the work done by the gravitational force when the mass $m$ is displaced by $d \vec s$.

Let $\hat r$ be the unit vector in the positive r-direction.

$\vec F = F \,\hat r$ and $d \vec s = dr\, \hat r$ where $F$ and $dr$ are components of $\vec F$ and $d \vec s$ in the $\hat r$ direction.

$\vec F \cdot d\vec s = F \,dr$

In your example $\vec F = -\dfrac{GMm}{r^2}$ and $dr$ is yet to be determined.

So what is the sign of $\vec F \cdot d\vec s = F \,dr = -\dfrac{GMm}{r^2} \, dr$?

That all depends on the sign of $dr$ which can either be positive or negative.

What determines the sign of $dr$?

The limits of integration will determine the sign of $dr$ during the process of integration.

In your example you move the particle from $r_1 \hat r$ to $r_2 \hat r$.

It does not matter at this stage whether $r_1 > r_2$ or $r_1 < r_2$ what you need to do is the integration.

$\displaystyle \int _{r_1}^{r_2} -\dfrac{GMm}{r^2} \, dr = GMm\ \left (\dfrac {1}{r_2} -\dfrac {1}{r_1} \right )$ and this is a positive quantity if $r_1 > r_2$.

You are integrating a vector field along a path, $\int_C \vec{F} \cdot d\vec{s}$, note that $\vec{F}(\vec{x})$ must be evaluated on the path $C$ along the integral and $d\vec{s}$ is actually the infinitesimal tangent of the path $C$

1. Crating a path. For sake of simplicity, we create path as the orange arrow, shown below. we will call it $C$.

the path is plot in Euclidean coordinate but the label is in the conventional the spherical coordinate $(r,\theta,\phi)$. the path is actually a parameterized vector $C: \vec{C}(t)=(r_1-t,0,0) ; t \in [0,r_1-r_2]$

1. The $d\vec{s}$ is $\frac{d\vec{C}}{dt}dt = (-1,0,0)dt$

2. The vector field must be evaluated on the path $C \rightarrow \vec{F}(r_1-t,0,0)$ in this case
$\vec{F}=\frac{GmM}{(r_1-t)^2}(-1,0,0)$

3. We are now got
$W=\int_{t=0}^{r_1-r_2} \frac{GmM}{(r_1-t)^2}(-1,0,0)\cdot(-1,0,0)dt$
$W=\int_{t=0}^{r_1-r_2} \frac{GmM}{(r_1-t)^2}dt$
$W=\frac{GmM}{(r_1-t)}|_{0}^{r_1-r_2}$
$W=GmM(\frac{1}{r_2}-\frac{1}{r_1}) > 0$ for $r_1>r_2$

Without changing to the spherical coordinate

$C: \vec{C}(t)=(r_1-t)\hat{z} ; t \in [0,r_1-r_2]$

$d\vec{s} = \frac{d\vec{C}}{dt}dt = -\hat{z} dt$

since $r$ in $\vec{F}$ is $\sqrt{x^2+y^2+z^2}$ but there is only $z$ here, so we will be fine

$\vec{F} = -\frac{GMm}{(r_1-t)^2}\hat{z};$ minus sign since the force is pointing toward origin (as we defined)

$W=\int_{t=0}^{r_1-r_2}\frac{GMm}{(r_1-t)^2}(-\hat{z})\cdot(-\hat{z})dt$

$W=\int_{t=0}^{r_1-r_2}\frac{GMm}{(r_1-t)^2}dt$

$W=GMm(\frac{1}{r_2}-\frac{1}{r_1})$