Mathematical Explanation of log(x^20) and 20 log(x) Plot

Hi all,

There is this weird thing since the formula saying that:

log (a^b) = b log(a)

But the plot says different:

But if we use calculator, the plot is correct, since we can plot log((-5)^20) just the same as the plot above. But x can’t be negative in 20 log(x)

using Plots, LaTeXStrings

f(x) = 20log(x) 
g(x) = 20/x
h(x) = log((x)^20)

plot(f, -10,20, ylims=(-100,100), label=L"y = 20 \ln (x)")
#plot(h, -10,20, ylims=(-100,100), label=L"y = \ln(x^{20})")
plot!(g, label=L"y=\frac{20}{x}")

Can anyone explain why the plot of supposedly same equation differs?

Given \ln(a^b) = b \ln(a) , let a=x and b=20. Then \ln(x^{20}) = 20 \ln x, not 20/x.

EDIT: The title of the post gets it right: log(x^20) and 20 log(x).


In short:
Log is not defined for negative numbers and 0.
Therefor the equivalence alog(b)=log(b^a) holds only for positive numbers b.


This happens because negative values of x are a valid argument for ln(x^20) because the value inside ln() will remain positive anyway. However, for ln(x) negative values of x are invalid, hence the graph is plotted only on positive side of x-axis.

Its not too rare that common known formulas are a bit imprecise and don’t hold in all cases, more often than not this happens when absoulute values are involved.

A better version of that formula would be

log (a^b) = b log(iseven(b) ? abs(a) : a)

but that is not as neat and harder to remember.


\frac{20}{x} is the differentiation of both the \ln (x^{20}) and 20 \ln (x), I put it in the plot to show the difference of plots of \ln (x^{20}) and 20 \ln (x), even if the differentiation is the same

1 Like

If I plot 20 \ln (|x|) the plot will be similar to \ln (x^{20}). It is true that it should be made positive to make the plots similar.