Original by Don Koks, 2017.

No, you can't.

This question has caused some angst in physics forums. Functions such as $\log$, $\exp$, and $\sin$ are not
defined for dimensioned quantities, and yet you will find expressions such as "$\log$ temperature" in physics text
books. Apparently *somebody* is taking the log of a dimensioned quantity, so what is going on?

Let's assume that maybe it's possible to take the logarithm of a dimensioned quantity. First, we go back to first principles to see how a logarithm is defined. The natural logarithm $\ln X$ is defined as the area under the curve $y = 1/x$ from $x = 1$ to $X$: \begin{equation} \ln X \equiv \int_{x\,=\,1}^X {\text{d}x\over x}\,. \end{equation} This integral is the sum of an infinite number of terms "$\text{d}x/x$", each of which is dimensionless. That means the logarithm is also dimensionless. We'll use this fact in the discussion that follows.

Suppose we set about attempting to take the logarithm of, say, 2 kilometres. We presume that this is the area under the curve $y = 1/x$ from $x = 1$ km to $x = 2$ km. Draw this curve by constructing an $x$ axis with its units in kilometres, and a $y$ axis with its units in kilometres$^{-1}$. Now think "Riemann sum": calculate the area by summing the areas of an infinite number of vertical bars drawn on the graph. Each bar's area is dimensionless. You will find that the (dimensionless) area is $\ln 2 \simeq 0.69$.

Now try taking the logarithm of 2000 metres in the same way. We presume that this is the area under the curve $y = 1/x$ from $x = 1$ metre to 2000 metres. Draw this curve by constructing an $x$ axis with units of metres and a $y$ axis with units of metres$^{-1}$, and then calculate the area as a limit of Riemann sums as above. You will find that the (dimensionless) area is $\ln 2000 \simeq 7.6$.

We have ended up with $\ln (2\text{ km}) \simeq 0.69$ and $\ln (2000\text{ m}) \simeq 7.6$.

You might expect $\ln (2\text{ km})$ to equal $\ln (2000\text{ m})$, but apparently that's not the case. This tells us immediately that taking the log of a dimensioned quantity as above is not useful, because the process doesn't respect a simple conversion from 2 km to 2000 m. What happened here? The problem was that in the first case, we started calculating the area from $x = 1$ kilometre; while in the second case, we started calculating the area from $x = 1$ metre. The simple fact is that the definition of the logarithm as an integral is a definition using dimensionless numbers. It doesn't "know" about dimensions, and so when we try to take the log of a dimensioned quantity, we end up with an ambiguity: where do we define the area to start?

What about the exponential function: can we give meaning to $\exp$ (2 km)? If we could, then we would notice that because the logarithm is dimensionless, it must be true that \begin{equation} \ln \left(e^{2\text{ km}}\right)\text{ is dimensionless,} \end{equation} and taking the $\exp$ of this (which we surely can do for dimensionless numbers!) would lead to $e^{2\text{ km}}$ being dimensionless. But if $e^{2\text{ km}}$ is dimensionless, then what did the exponential function do with the kilometre unit? Presumably whatever it did, it would do the same with a unit of a metre. Apparently then, the exponential function cannot distinguish between $e^{2\text{ km}}$ and $e^{2\text{ m}}$. That means it also can't distinguish between $e^{2000\text{ km}}$ and $e^{2000\text{ m}}$. And that means we can expect $e^{2\text{ km}}$ to differ from $e^{2000\text{ m}}$: so, again, something has broken. Just like the logarithm, the exponential function doesn't "know" about dimensions, and so when we try to include dimensions, things fall apart.

You might come across the following argument: "$e^{2\text{ m}}$ can make no sense, because it must be writable as
the exponential series
\begin{equation}
\exp (2\text{ m}) = 1 + 2\text{ m} + {2^2\text{ m}^2\over 2\textit{!}} +
{2^3\text{ m}^3\over 3\textit{!}} + \dots\,,
\end{equation}
and since we cannot add 1 to a metre to a square metre and so on, the series is undefined." This looks
reasonable, but in fact the situation is more complicated because the exponential series is a Taylor series, and all
terms of a Taylor series *must* have the same dimension. For example, write
\begin{equation}
\exp x = \exp 0 + \exp'(0) x + {\exp''(0) x^2\over 2\textit{!}} + \dots\,,
\end{equation}
and now notice that $\exp'(x) = \text{d}\exp x/\text{d}x$, whose dimension is that of $\exp x$ divided by the
dimension of $x$, which is length. Similarly, the dimension of $\exp''(x) = \text{d}\exp'(x)/\text{d}x$ is
the dimension of $\exp x$ divided by the dimension of length$^2$. So if we insist on including dimensions
everywhere, we are no longer able to say "$\exp'(x) = \exp x$". The bottom line is that if we insist on allowing
$\exp$ to be taken of dimensioned quantities, the calculus that we are so familiar with starts to crumble.

With all of that said, you will sometimes find the logarithm of a dimensioned quantity taken in textbooks.
Here's what is going on there. Suppose we have some set-up involving heat flow in one dimension that's governed
by the following differential equation:
\begin{equation} \label{eqn1}
{\text{d}T\over \text{d}x} = {c\over x}\,,
\end{equation}
where $T$ is temperature, $x$ is distance from some origin, and *c* is a constant to be determined. We
wish to solve this equation. Begin by writing it as
\begin{equation} \label{eqn2}
\text{d}T = c\, {\text{d}x\over x}\,.
\end{equation}
Now integrate both sides. We cannot simply write "$T = c\ln x + \text{constant}$" because we cannot take the
logarithm of $x$, since $x$ has dimension (of length). In what follows, we will always only write the logarithm
of a quantity that is dimensionless. So notice that for any $x_0$ (with dimension of length),
\begin{equation}
{\text{d}\over \text{d}x} \ln {x\over x_0} = {x_0\over x}\times {1\over x_0} = {1\over x}\,.
\end{equation}
That lets us integrate \eqref{eqn2} to give
\begin{equation} \label{eqn4}
T(x) = c \ln {x\over x_0} + c_1\,,
\end{equation}
for some constant $c_1$. Now set $x = x_0$ in \eqref{eqn4}:
\begin{equation}
T(x_0) = c_1\,.
\end{equation}
Thus \eqref{eqn4} can be written as
\begin{equation} \label{eqn5}
T(x) = c \ln {x\over x_0} + T(x_0)\,.
\end{equation}
We're almost there. Now, suppose we measure the temperature at $x = 10$ m to be $T = 10$ K. Set $x_0 = 10$
m in
\eqref{eqn5}:
\begin{equation} \label{eqn6}
T(x) = c \ln {x\over 10\text{ m}} + 10\text{ K}\,.
\end{equation}
We don't yet know the value of $c$, so we make another measurement: e.g. we measure the temperature at $x = 20$ m to
be $T = 20$ K. Substitute these into \eqref{eqn6} to give
\begin{align}
20\text{ K} &= c\ln{20\text{ m}\over 10\text{ m}} + 10\text{ K}\\[1ex]
&= c\ln 2 + 10\text{ K}\,,
\end{align}
in which case
\begin{equation}
c = {10\text{ K}\over \ln 2} \simeq 14.4\text{ K}\,.
\end{equation}
Now substitute this value of $c$ into \eqref{eqn6} to give the sought-after expression for temperature $T$ as
a function of position $x$, that does not refer to any $x_0$:
\begin{equation} \label{eqn7}
T(x) = \left(14.4 \ln{x\over 10\text{ m}}+10\right)\text{K}\,.
\end{equation}
We can divide both sides of \eqref{eqn7} by 1 kelvin to write
\begin{equation} \label{eqn8}
{T(x)\over 1\text{ K}} = 14.4\ln {x\over 10\text{ m}}+10\,.
\end{equation}

Equations \eqref{eqn7} or \eqref{eqn8} are the solution to the original problem of calculating the temperature $T(x)$. But study carefully what we can do next. Always ensuring we take the logarithm only of dimensioned quantities, \eqref{eqn8} can be written as \begin{align} {T(x)\over 1\text{ K}} &= 14.4\ln{x/(1\text{ m})\over 10\text{ m}/(1\text{ m})} + 10\\[1ex] &= 14.4\ln{x\over 1\text{ m}} - 14.4 \ln 10 + 10\\[1ex] &= 14.4\ln{x\over 1\text{ m}} - 23.2\,.\label{eqn9} \end{align}

Now, think of what division means: just as the expression 6/2 denotes the number of 2s in 6 (i.e. 3), so also $x/(1\text{ m})$ means "the number of metres in $x$", i.e. "$x$ expressed in metres". Similarly, $T/(1\text{ K})$ means "$T$ expressed in kelvins". So \eqref{eqn9} can be written as \begin{equation} \label{eqn10} T\text{ expressed in kelvins} = 14.4 \ln (x\text{ expressed in metres}) - 23.2\,. \end{equation}

Now if we agree to use the above units—that is, SI units (but we could've used any other system of units instead)—then we can all agree to abbreviate \eqref{eqn10} to \begin{equation} \label{eqn11} T = 14.4 \ln x - 23.2\,. \end{equation}

For the two data points we mentioned above, $(x,T) = (10\text{ m}, 10\text{ K})$ and $(20\text{ m}, 20\text{ K})$,
equation \eqref{eqn11} is how the solution to \eqref{eqn1} would be written in many physics books, where the caveat
"where $T$ and $x$ are expressed in SI units" may or may not be added. So the $x$ in \eqref{eqn11} really means
"$x$ expressed in metres", which is a pure number: the number of metres in $x$, so it's *dimensionless*.
And likewise, the $T$ in \eqref{eqn11} really means "$T$ expressed in kelvins": this is a pure number, and so is
dimensionless. Hence, although it looks as if we are taking the log of a dimensioned quantity $x$, in fact we are
not, because $x$ is no longer a length; rather, it's the number of metres in the length that we started out calling
$x$. If that's confusing, I'm not defending it here; it's just what some books do. But provided we all
know the game that's being played, there's no real problem.

You can also see that if you return to \eqref{eqn2} and integrate it by pretending that $T$ and $x$ are pure numbers, you will get \begin{equation} T = c \ln x + c_1\,. \end{equation} If you now mandate that $T$ and $x$ are to be expressed in SI units and make use of the two measured data points, you will eventually arrive at \eqref{eqn11} again. This is, in fact, what most (if not all) textbooks actually do. And maybe it's a pity they do that, because whereas that approach is quick and direct, it leaves many readers thinking, incorrectly, that the logarithm has been taken of a dimensioned quantity.

Now suppose you have some data of $(x, T)$, and you wish to test the validity of the theory that produced the differential equation \eqref{eqn1}. Referring to \eqref{eqn9}, you wish to plot $T/(1\text{ K})$ versus $\ln [x/(1\text{ m})]$, then measure the slope to find that it has value 14.4 (dimensionless!), with a "$y$-intercept" of $-23.2$ (dimensionless!). How will you label your axes?

Your horizontal axis is $\ln [x/(1\text{ m})]$, which is dimensionless. Just label it as "$\ln [x/(1\text{
m})]$", and there are no units needing to be written here. Your vertical axis is $T/(1\text{ K})$. That's
dimensionless too, and you can label it "$T/(1\text{ K})$". You can also label it "$T$ (kelvins)", while
realising that now you are plotting $T$, which has a dimension—in which case your slope will now have units of
kelvins. You have this freedom in what to plot on the vertical axis, but *don't* label your horizontal
axis with anything like "$\ln x$ (log metres)", because this is simply wrong: (a) "$\ln x$" for $x$ dimensioned is not
defined, and (b) there is no such unit as a "log metre". Unfortunately, you will find occurrences of similar
wrong units in some place or other, written by someone who doesn't realise that they are really plotting $\ln
[x/(1\text{ m})]$ and not $\ln x$. (If you look carefully, you can even see "log kelvins" next to a plot on a
whiteboard in an episode of the TV series "The Big Bang Theory".)

The take-home message here is that the correct way to convert the sentence "$A$ is measured in metres" (or whatever unit you wish to write here) into maths is to write the dimensionless quantity "$A/(1\text{ m})$". That's a fraction like any other, and it can be treated completely analytically. Try using it to convert something from metres to, say, inches.

Finally, don't waste any time trying to extend the definition of the logarithm by experimenting with statements such as "$\ln (2\text{ m}) = \ln 2 + \ln (\text{m})$", as some try to do. Once you have finished getting nowhere with that, how will you then tackle "$\sin (1\text{ m})$"? The simple fact is that no function needs its definition extended to cope with units, because the standard functions used throughout maths and physics—which all act on dimensionless numbers and return a dimensionless number—are always sufficient for any job involving units, just as the logarithm is.