AP Calculus BC

Integral of (ln x)^2: Integration by Parts Twice

The integral of ln x squared, meaning ln x all squared, is x times ln x squared, minus 2x ln x, plus 2x, plus C. Integration by parts runs twice: u is (ln x) squared on the first pass and ln x on the second, and each pass removes one power of the logarithm.

(lnx)2dx=x(lnx)22xlnx+2x+C\int \left(\ln x\right)^{2}\,dx = x\left(\ln x\right)^{2} - 2x\ln x + 2x + C

Parts, then parts again

There is no second factor to hand, so take dv=dxdv = dx. With u=(lnx)2u = \left(\ln x\right)^{2} that gives v=xv = x and du=2lnxxdxdu = \frac{2\ln x}{x}\,dx.

(lnx)2dx=x(lnx)2x2lnxxdx=x(lnx)22lnxdx\int\left(\ln x\right)^{2}dx = x\left(\ln x\right)^{2} - \int x\cdot\frac{2\ln x}{x}\,dx = x\left(\ln x\right)^{2} - 2\int\ln x\,dx

What is left is the standard logarithm integral, and it is a parts problem in its own right with u=lnxu = \ln x and dv=dxdv = dx.

lnxdx=xlnxx\int\ln x\,dx = x\ln x - x
(lnx)2dx=x(lnx)22xlnx+2x+C\int\left(\ln x\right)^{2}dx = x\left(\ln x\right)^{2} - 2x\ln x + 2x + C

One power per pass

The structure generalises. Parts on (lnx)n\left(\ln x\right)^{n} with dv=dxdv = dx leaves n(lnx)n1dxn\int\left(\ln x\right)^{n-1}dx, so the exponent drops by one every time and the process ends after nn passes. Knowing that in advance tells you how long the problem will take before you start it.

(ln x)^2 is not ln(x^2)

ln(x^2) equals 2 ln|x| by the power law for logarithms, so its integral is 2x ln|x| - 2x + C in a single line. The bars matter: ln(x^2) is defined for every x other than 0, while (ln x)^2 needs x > 0, and that wider domain is the deeper reason the two problems differ. The squared logarithm also needs two passes. One pair of brackets decides which problem you are solving.

The mistakes students make

Each of these ends in a clean looking expression, so checking by differentiation matters more than usual on this one.

  • Reading (lnx)2\left(\ln x\right)^{2} as ln(x2)\ln\left(x^{2}\right) and answering 2xlnx2x2x\ln\left|x\right| - 2x, which is the integral of a different function.
  • Reaching for the power rule and writing (lnx)33\frac{\left(\ln x\right)^{3}}{3}. Differentiating that gives (lnx)2x\frac{\left(\ln x\right)^{2}}{x}, not (lnx)2\left(\ln x\right)^{2}.
  • Multiplying the second term by 22 but keeping its minus sign, finishing with x(lnx)22xlnx2xx\left(\ln x\right)^{2} - 2x\ln x - 2x. The 2-2 multiplies both parts of xlnxxx\ln x - x, so the sign on the last term flips to positive.

Every answer on this page is machine checked

An automated test differentiates the antiderivative above and confirms it returns the integrand. A wrong sign or a missing factor fails the build, so it cannot reach you.

Frequently asked questions

What is the integral of ln^2 x?

It is x(lnx)22xlnx+2x+Cx\left(\ln x\right)^{2} - 2x\ln x + 2x + C, for x>0x > 0.

Why does this need integration by parts twice?

The first pass converts (lnx)2\left(\ln x\right)^{2} into 2lnxdx2\int\ln x\,dx, and that integral is itself a parts problem. Each pass strips one power off the logarithm.

Is the integral of (ln x)^2 the same as the integral of ln(x^2)?

No. ln(x2)=2lnx\ln\left(x^{2}\right) = 2\ln\left|x\right|, whose integral is 2xlnx2x+C2x\ln\left|x\right| - 2x + C. The squared logarithm gives x(lnx)22xlnx+2x+Cx\left(\ln x\right)^{2} - 2x\ln x + 2x + C, and it is defined only for x>0x > 0 while ln(x2)\ln\left(x^{2}\right) is defined for every x0x \ne 0.