# How to solve this logarithmic equation?

The equation $$x^2\cdot\log_2\dfrac{3+x}{10}-x^2\cdot\log_{\frac{1}{2}}(2 + 3x)=x^2 - 4+2\cdot\log_{\sqrt{2}}\dfrac{3x^2+11x+6}{10}$$ has two solutions for x, namely 1 and 2. I tried

Reduce[x^2*Log[2, (3 + x)/10] - x^2*Log[1/2, 2 + 3*x] ==
x^2 - 4 + 2*Log[Sqrt[2], (3*x^2 + 11*x + 6)/10], x]


and

Solve[x^2*Log[2, (3 + x)/10] - x^2*Log[1/2, 2 + 3*x] ==
x^2 - 4 + 2*Log[Sqrt[2], (3*x^2 + 11*x + 6)/10], x]


but I could not get these two solutions. How do I tell Mathematica to do that?

• Try FindRoot or this ? Commented Oct 21, 2012 at 15:26
• What you have there is a (rather complicated) transcendental equation; in a situation like this, it is often profitable to help Mathematica out and try to do a few simplifications of your own before feeding equations to a solver... Commented Oct 21, 2012 at 15:44
• minthao, you were a bit fast accepting the first given answer (and not only because I added mine later ;-) ). It is usually a good idea to wait a couple of hours or even days for your accept so that more people might be tempted to react. Commented Oct 21, 2012 at 17:25

Here's a way to do it numerically. It uses the adaptive sampling Plot uses to determine the approximate positions of the roots.

Here's the expression:

expr = x^2*Log[2, (3 + x)/10] -
x^2*Log[1/2, 2 + 3*x] - (x^2 - 4 +
2*Log[Sqrt[2], (3*x^2 + 11*x + 6)/10]);


We'll solve for expr==0. We look for roots between

xlow = 0; xhigh = 3;


To do that, ask Plot to plot the expression, then extract the list of data points:

(points =
Cases[Normal[Plot[expr, {x, xlow, xhigh}]], Line[l_] :> l,
Infinity] // First) // Shallow


These are the points Plot uses. You can ListPlot them to see the adaptive sampling at play.

Now, we need to locate which two points bracket a root, which means that their y-coordinates have opposite signs; so check for this:

signChanges = Position[
Times @@ ## & /@ Partition[points[[All, 2]], 2, 1],
x_ /; x < 0
] // Flatten

{23, 232}


and finally use FindRoot giving it a range to search in:

FindRoot[expr == 0, {x, points[[#, 1]], points[[# + 1, 1]]}] & /@ signChanges
{{x -> 1.}, {x -> 2.}}


EDIT: changed the way the points are obtained after discussion with Artes and JM

• Reminds me... Commented Oct 21, 2012 at 15:53
• @J.M. yes, I had seen it some time ago. This is what I do when I need many roots of 1d functions, so I thought I'd give a quick demonstration here.
– acl
Commented Oct 21, 2012 at 16:06
• @acl you might be interested in my answer Commented Oct 21, 2012 at 17:19
• @acl When I evaluate all input in your answer and then evaluating (points = Plot[expr, {x, xlow, xhigh}][[1, 1, 3, 3, 1]]) // Shallow I get Part::partw: Part 3 of {Hue[0.67,0.6,0.6],Line[{{6.12245*10^-8,6.94786},{0.000920154,6.93813},{0.00184025,6.92841},{0.00368043,6.90899},<<44>>,{1.29535,-0.785195},{1.3027,-0.796846},<<220>>}]} does not exist. >> and then everything fails. Commented Oct 21, 2012 at 19:43
• @Artes strange, I just copied the expression in your comment and it does work. what version of mma are you using? have you set any default options on Plot?
– acl
Commented Oct 21, 2012 at 20:44

This equation has many more 'nice' valued roots than you think. Let's see what a man-machine cooperation can find. I'm going to take fairly rough steps and back-substitute the results to see whether I stepped on any mathematician's toes in the process.

First, let's move everything to one side of the equation and whisk everything on that side together:

 (Exp[x^2*Log[2, (3 + x)/10] - x^2*Log[1/2, 2 + 3*x]] -
Exp[x^2 - 4 + 2*Log[Sqrt[2], (3*x^2 + 11*x + 6)/10]]) // Together


(1)

Since it is easy to see that (3+x)(2+3*x) == (6 + 11 x + 3 x^2) the right hand part of the above equation equals zero if (6 + 11 x + 3 x^2)==0.

Solve[6 + 11 x + 3 x^2 == 0, x]


{{x -> -3}, {x -> -(2/3)}}

Let's further explore that part of the numerator of (1). We take the log of both parts (allowed because the whole term between parenthesis should equal zero, add a few minus signs to make everything still zero). Rewrite the logs using a few rules for logarithms:

  Log[-10^((4/Log[2])) E^4 (3 + x)^(x^2/Log[2]) (2 + 3 x)^(x^2/Log[2])] -
Log[-10^((x^2/Log[2])) E^x^2 (6 + 11 x + 3 x^2)^(4/Log[2])]
//. {Log[a_ b_] -> Log[a] + Log[b], Log[a_^b_] -> b Log[a]}


Again, looking through your eye lashes you notice you can factor out a term (4-x^2):

The first part has solutions $\pm 2$, of course, and for the second part we find:

Solve[ 1 + Log[10]/Log[2] - Log[6 + 11 x + 3 x^2]/Log[2] == 0, x]

{{x -> -(14/3)}, {x -> 1}}


Back-substituting all solutions in your equation:

x^2*Log[2, (3 + x)/10] - x^2*Log[1/2, 2 + 3*x] ==
x^2 - 4 + 2*Log[Sqrt[2], (3*x^2 + 11*x + 6)/10]
/. {{x -> -14/3}, {x -> -2}, {x -> 2},
{x ->  1}, {x -> -3}, {x -> -2/3}} // FullSimplify


{False, True, True, True, True, True}

So, we have solutions for x = -3,-2, -2/3, 1, and 2.

However, as acl, Artes and Whuber have pointed out, some of these have a problem. For x =-3 we get a Log[2,0] in the first term of the left-hand side of the equation that Mathematica cancels with another Log[0]; same for the second term and x = -2/3. The situation for x=-2 is different. You get logs of negative numbers like Log[-4] which have a complex answer that depending on the branch cut definition that is being used. In this case we get I Pi + Log[4]. If you do Exp[I Pi + Log[4]], you get -4. So, depending on your stance on branch cuts you might consider the full set of solution to be {-2, 1, 2}. And if you don't like the first one, we've still found 1 and 2 as exact values, not with numerical root finding approximations.

• $-3$ and $-2/3$ are "solutions" only in an unconventional sense that Mathematica evaluates both sides to "$-\infty$". $-2$ is a solution only for a particular convention concerning logarithms of negative numbers, which one ordinarily should be cautious about and at least deserves a flag. Commented Oct 21, 2012 at 21:27
• If you plot Plot[Abs@expr, {x, -5, 5}] (with expr as in my answer) you can see it's inconsistent with this result. I don't have time to work out what is going on, but, as always when there are logs involved, Mathematica is probably doing something dodgy with the branch cuts. minimizing the risk of such problems is why I did this numerically and in the real domain. (no I didn't downvote this).
– acl
Commented Oct 21, 2012 at 21:35
• Now it seems OK, -2 is not a singular point but one shouldn't consider this to be a solution, (I haven't downvoted your answer) Exp[-2 + 2 Pi I] == Exp[-2], using Simplify or FullSimplify on f[-2] you can get 0 because of the nature of these functions (they cancel nonuniqueness of Log). Reduce and Solve are free of that ambiguity. Commented Oct 21, 2012 at 22:40

The most reliable approach to the problem uses Reduce, one can also use Solve. However one should restrict the complex domain to a compact subset or should add the domain specifications like e.g. Reals, remembering that Mathematica treats numbers as complex in general.

In Mathematica 7 Root had been considerably updated to include these capabilities:

Root[{f, x0}] represents an exact root of the general equation f[x]==0, which can be transcendental.

In Root[{f, x0}], x0 must be an approximate real or complex number such that exactly one root of f[x] lies within the numerical region defined by its precision.

Root[{f, x0, n}] represents n roots, counting multiplicity, that lie within the numerical region defined by the precision of x0.

Let's define f :

f[x_] := x^2 Log[2, (3 + x)/10] - x^2 Log[1/2, 2 + 3 x] - x^2 + 4
- 2 Log[Sqrt[2], (3 x^2 + 11 x + 6)/10]

Reduce[ f[x] == 0, x, Reals]

x == Root[{-4Log[2] + Log[(6 + 11#1 + 3 #1^2)^4/10000] + Log[20/((3 +#1) (2 + 3#1))] #1^2 &,
0.999999999999999999998}] ||
x == Root[{-4Log[2] + Log[(6 + 11#1 + 3#1^2)^4/10000] + Log[20/((3 + #1) (2 + 3#1))] #1^2 &,
2.0000000000000000000}]

N[ %, 30]

x == 1.00000000000000000000000000000 || x == 2.00000000000000000000000000000


We can find solutions in appropriately restricted complex plain, but then neither Reduce nor Solve can prove that the solution set is complete :

Solve[ f[x] == 0 && -5 < Re[x] < 5 && -5 < Im[x] < 5, x]

Solve::incs: Warning: Solve was unable to prove that the solution set found is complete. >>

{{x -> 2},
{x -> Root[{-4Log[2] + 4Log[1/10 (6 + 11 #1 + 3 #1^2)] + Log[2] #1^2
- Log[(3 + #1)/10] #1^2 - Log[2 + 3 #1] #1^2 &,
1.000000000000000000000000000000}]}}


One might wonder that using e.g. f[-2] // Simplify yields 0 but there is no root -2 in the output of Reduce, even though we can see this :

Plot[{ Re @ f[x], Im @ f[x]}, {x, -5, 5}, PlotStyle -> Thick, Evaluated -> True]


The reason is that logarithm is not well defined in the whole complex plain, there must be certain branch cut or more generally one should view it as a function on a Riemann surface. Therefore we should rely on the Reduce output rather than on Simplify.

• This doesn't find all the solutions that I found. See my answer. Commented Oct 21, 2012 at 18:05
• No, these methods (Solve, Reduce) are more reliable than yours, these are not the solutions to the given equation, but to that transformed one. That is because e.g. Log[2, 0] yields -Infinity, etc.. Commented Oct 21, 2012 at 19:18
• What transformed one? If you read my answer (esp. the bottom part) you'll see that I back-substituted all solutions in the original equation and five of them really seem to be solutions. Try it yourself. Commented Oct 21, 2012 at 19:40
• @SjoerdC.deVries I don't agree. The issue that Mathematica yields True is wrong. You can check e.g. x^2*Log[2, (3 + x)/10] - x^2*Log[1/2, 2 + 3*x] /. {{x -> -2}, {x -> 2}, {x -> 1}, {x -> -3}, {x -> -2/3}} // FullSimplify. Consider e.g. f[x_] := x^2 Log[2, (3 + x)/10] - x^2 Log[1/2, 2 + 3 x] - x^2 + 4 - 2 Log[Sqrt[2], (3 x^2 + 11 x + 6)/10]. These -3,-2, -2/3 are singular points of f. Apparently we get unacceptable subtracting of infinities in Mathematica. Commented Oct 21, 2012 at 19:58
• @minthao_2011 Look at this answer to a related problem : mathematica.stackexchange.com/questions/4694/… Commented Oct 21, 2012 at 23:44

Taking to heart the advice given by J.M. in a comment to the question, after finding that the brute-force method of just asking for a solution falls short, we might consider using Mathematica as a tool to support the operations we would think of carrying out when solving such an equation.

Staring at the equation suggests several methods might be fruitful:

1. Subtracting one side from the other, thereby enabling one expression to be simplified fully.

2. Perhaps finding common factors among the polynomial subexpressions. This would primarily involve factoring the highest-degree polynomial, $3x^2 + 11x + 6$.

3. Exploiting the multiplicative property of logarithms, $\log(uv)=\log(u)+\log(v)$.

$Mathematica$ could use a little nudging in all these directions.

### Developing solutions

Begin with the original equation:

f[x_] := x^2*Log[2, (3 + x)/10] - x^2*Log[1/2, 2 + 3*x] ==
x^2 - 4 + 2*Log[Sqrt[2], (3*x^2 + 11*x + 6)/10]


$\frac{x^2 \log \left(\frac{x+3}{10}\right)}{\log (2)}+\frac{x^2 \log (3 x+2)}{\log (2)}=x^2+\frac{4 \log \left(\frac{1}{10} \left(3 x^2+11 x+6\right)\right)}{\log (2)}-4$

Apply the three rules. We will be looking for zeros of g:

g[x_] := Evaluate[Replace[Together[f[x] /. u_ == v_ -> u - v] , u_Plus :>  Factor[u], Infinity]
//. Log[u_ v_] -> (Log[u] + Log[v]) // Simplify]


$\frac{\left(x^2-4\right) \left(\log \left(\frac{x+3}{20}\right)+\log (3 x+2)\right)}{\log (2)}$

It looks a lot simpler (you can practically read all the solutions directly from this form), so let's try with Solve once more:

Solve[g[x] == 0, x, Reals]


{{x -> 1}, {x -> 2}}

If solutions found using Complex arithmetic are desired, unfetter Solve by removing the last option:

Solve[g[x] == 0, x]


{{x -> -2}, {x -> 1}, {x -> 2}}

As a check, one can plot $g$ in the neighborhood of the putative solutions and look for crossings of the x-axis.

Plot[g[x], {x, -3, 3}]


### Checking the solutions

Surprisingly, a direct check of the solutions fails:

f /@ {-2, 1, 2}


{False, False, False}

Tracing the function identifies the problem:

Trace[f[#]][[-2 ;;]] & /@ {-2, 1, 2}


$\left\{\left\{\frac{4 (i \pi +\text{Log}[4])}{\text{Log}[2]}-\frac{4 \text{Log}[10]}{\text{Log}[2]}==\frac{4 \left(i \pi -\text{Log}\left[\frac{5}{2}\right]\right)}{\text{Log}[2]},\text{False}\right\},\left\{-\frac{\text{Log}\left[\frac{5}{2}\right]}{\text{Log}[2]}+\frac{\text{Log}[5]}{\text{Log}[2]}==1,\text{False}\right\},\left\{8==\frac{4 \text{Log}[4]}{\text{Log}[2]},\text{False}\right\}\right\}$

For some reason, the penultimate expressions do not evaluate correctly. Although other threads have been related to similar problems with logarithms (such as simplifying $\frac{\log x^a}{a} = \log x$), they do not appear fully to discuss why expressions like, say, 3 == Log[8]/Log[2] evaluate to False whereas (3 - Log[8]/Log[2] // Simplify) == 0 will evaluate to True. This apparent contradiction casts doubt on the easy--but probably not fully correct--explanation that the logarithm is a many-valued function.