By definition of the gravitational energy:

$$
-\frac{dU}{dx}=-\frac{GMm}{x^2}=F
$$

Then by integrating we get:

$$
U(x)=\int\frac{GMm}{x^2}=-\frac{GMm}{x}
$$

**(I am not confused why force is negative derivative of the potential function)**

I am confused about the negative sign in front of the **force** here in the first equation.I know that in force vector there should be a negative sign to indicate the opposite direction to unit vector. But isn't the whole equation just in **scalar form**?

(See both function $U$ and variable $x$ are scalars)

So why do we put minus sign here? Even if it is in vector form,how do we define the direction $dx$ and how does it relate to the unit vector in $F$ (which makes a minus sign in F's vector equation).

I know that physically work done equals to negative change in potential function, and it makes sense in this equation. But I wish to get a mathematical explanation.

And, I have an another question, when using line integral to find work done by the field:

$$
w=\int\_c \mathbf{F}\cdot\mathrm{d}\mathbf{r}
$$

Where $\mathrm{d}\mathbf{r}$ here is the element for position vector, if we goes from a larger radius to a smaller radius, the force vector should have same direction to change in position vector, therefore the work done:

$$
w=\int\_c \mathbf{F}\cdot\mathrm{d}\mathbf{r}=\int\_{R\_2}^{R\_1}\frac{GMm}{R^2}\mathrm{d}R=\frac{GMm}{R\_2}-\frac{GMm}{R\_1}
$$

When I goes from smaller radius to a lager radius, the formula becomes:

$$
w=\int\_c \mathbf{F}\cdot\mathrm{d}\mathbf{r}=\int\_{R\_1}^{R\_2}-\frac{GMm}{R^2}\mathrm{d}R=\frac{GMm}{R\_2}-\frac{GMm}{R\_1}
$$

Where $\mathrm{d}\mathbf{r}$ is **positional vector**, $\mathrm{d}R$ is the **radius element** and $R\_2>R\_1$. The position vector should be reversible to each other because of the direction we choose. See the work done here becomes same, but we know that gravity is conservative, so the two outcomes here should just be reversible to each other.

What goes wrong with my deductions here? Hope that you can solve my problem, and please forgive my ignorance as I am just a high school student.