# Problem with Plot

The command

Plot[Log[27, Sin[2*x] - 1/3*Cos[x]] - 1/3*Log[3, -Cos[x]], {x, -Pi, Pi}]


performs

However, this result contradicts both calculus over the reals, where $\log_3(-\cos x)$ is not defined for $x\ge-\frac \pi 2, x\le \frac \pi 2,$ and the result of

Solve[Log[27, Sin[2*x] - 1/3*Cos[x]] - 1/3*Log[3, -Cos[x]] == 0 &&
x >= -Pi && x < Pi, x, Reals]


{{x -> -2 ArcTan[3 + 2 Sqrt[2]]}}

The question arises: how to fix this discordance?

f = Module[{l}, l = Log[#, ConditionalExpression[#2, #2 > 0]] &; With[{Log = l}, #]]&;

f @ Unevaluated @ Plot[Log[27, Sin[2*x] - 1/3*Cos[x]] - 1/3*Log[3, -Cos[x]], {x, -Pi, Pi}]


Alternatively,

g = ConditionalExpression[#, Simplify[FunctionDomain[#, x] /. C[1] -> 0]]&;

Plot[Evaluate[g@Log[27, Sin[2*x] - 1/3*Cos[x]] - 1/3*Log[3, -Cos[x]]], {x, -Pi,  Pi}]


same picture

• Thank you. This works well. However, the main work is done by hand, not automatically. I think the FunctionDomain command works better here. – user64494 Sep 7 '18 at 7:03
• @user64494, added a variant that uses FunctionDomain. – kglr Sep 7 '18 at 7:38
• Thank you again. I am interested in a simple answer: students are not two-headed. – user64494 Sep 7 '18 at 7:40
• Your answer is professionally done and automated. Unfortunately, its understanding is difficult for undegraduate students. It is impossible to accept two answers simultaneously. Because of this reason I abstain of its accepting as yet. – user64494 Sep 7 '18 at 14:14

Your plotfunction is real if both Log-arguments are >0. Perhaps using RegionFunctions might help solving your problem:

Plot[ Log[27, Sin[2*x] - 1/3*Cos[x]] -1/3*Log[3, -Cos[x]] , {x, -2 Pi, 2 Pi},PlotRange -> {{-2 Pi, 2 Pi}, Automatic},PlotLabel -> "both log arguments >0",
RegionFunction ->Function[x, (Sin[2*x] - 1/3*Cos[x] > 0) && ( -Cos[x] > 0)] ]


But the sum of two comlex numbers might although evaluate to real, if the summands are complex:

Plot[{ #, Im[#]} &[Log[27, Sin[2*x] - 1/3*Cos[x]] - 1/3*Log[3, -Cos[x]]] // Evaluate, {x, -2 Pi, 2 Pi}, PlotStyle -> {{ Red}, Green }]


and that's the result MMA calculates in the first plot of the question.

By the way it's identical to the use of RegionFunction -> Function[{x, y}, Im[y] == 0]

Plot[ Log[27, Sin[2*x] - 1/3*Cos[x]] -1/3*Log[3, -Cos[x]] , {x, -2 Pi, 2 Pi}, PlotRange -> All,
RegionFunction -> Function[{x, y},  Im[y] == 0], PlotRange -> All, PlotLabel -> "Im==0"]

• Thank you. This works well. However, main work is done by hand, not automatically, so I wiil be waiting for other answers some time before accepting your answer.. – user64494 Sep 7 '18 at 6:35
• Your answer is clear and understable to undegraduate students. However, its main part is done rather by hand. Unfortunately, it is impossible to accept two answers simultaneously. Because of this reason I abstain of its accepting as yet. – user64494 Sep 7 '18 at 14:15
• @user64494 Thanks for your reply. If you look at the last code line in my answer you might recognize , that it is quite straight forward(nothing made by hand...) – Ulrich Neumann Sep 7 '18 at 14:31
• Yes, it is a direct code. Unfortunately, this code does not produce the required plot. – user64494 Sep 7 '18 at 17:03
• @ user64494 What is the required plot? Should the plotfunction be real? If yes it is the required plot!!! Or should the several log-functions be simultanously real? If so, the answer of kglr and the first result of my answer is what you are looking for!!!! – Ulrich Neumann Sep 7 '18 at 19:01