# log/exponential question

• February 19th 2011, 05:15 PM
crossbone
log/exponential question
How to solve $\log(x)=-x$? log is base e
• February 19th 2011, 05:19 PM
topsquark
Quote:

Originally Posted by crossbone
How to solve $\log(x)=-x$? log is base e

Numerically. There is no analytic way to solve this.

-Dan
• February 19th 2011, 05:22 PM
crossbone
where do you start numerically? I know the solution must be between 0 and 1.
• February 19th 2011, 05:59 PM
SammyS
Look at the roots of the function: $f(x)=x+\log(x)\,.$

Try $f(1/2)=-0.1931...\,.$ That's negative. $f(1)=1\,.$ That's positive, so the root is between 1/2 and 1.

Use linear interpolation or the bisection method.
• February 20th 2011, 03:54 AM
HallsofIvy
Whether or not you can solve it "analytically" depends upon what you mean by "analytically". From $log(x)= -x$ we get $x= e^{-x}$ and the $xe^x= 1$. From that, $x= W(1)$ where "W" is the "Lambert W function" which is defined as the inverse function to $f(x)= xe^x$. Of course, values of the W function are calculated numerically, just as values of logarithms, exponentials, or trig functions are.

"Linear Interpolation", that Sammy S referred to, is also called the "secant method" since you use a line between two points on the curve to approximate the curve rather than the tangent line as Newton's method does. Now that you know that (0.5, -0.9131) and (1, 1) are on the curve, you could calculate the straight line between those two points and and determine where that line crosses the y-axis. Take that together with either 0.5 or 1, depending upon whether the actual value of the function is positive or negative, and do it again.

If you don't have a computer doing the calculations for you "bisection" is simpler. As SammyS calculated, f(.5)= -0.9131< and f(1)= 1> 0 (f(x)= x+ ln(x)) so there must be a 0 between them. The simplest thing to do is to take half way between: 0.75. Now f(0.75)= 0.75+ ln(0.75)= 0.46231> 0. So there must be a root between 0.5 and 0.75. Half way between is 0.625. Continue until you have an accurate enough result.