# Solving a transcendental equation

I want to solve the a transcendental equation, e.g.

NSolve[-(1-x)*Log[1-x] - x*Log[x] == 0.5, x]


Mathematica is not able to solve, wheres WolframAlpha -- is able to do it.

The purpose it to find the probabilities for two events in accordance to a given entropy value.

• Try FindRoot instead (look it up in the help pages). And be careful that there is a space or a * between x and Log[x] in your expression. Commented Jul 6, 2015 at 20:04
• In particular, Chop@FindRoot[-(1 - x) Log[1 - x] - x Log[x] == 0.5, {x, 2}] gives an answer of 0.80029. FindRoot is preferable to NSolve for most transcendental equations. Commented Jul 6, 2015 at 20:07
• NSolve[-(1 - x)*Log[1 - x] - x*Log[x] == 0.5, x, Reals] ? Commented Jul 6, 2015 at 20:13

Reduce[-(1 - x) Log[1 - x] - x*Log[x] == 1/2, x, Reals]
(*
x == Root[{-1 - 2 Log[#1] #1 + Log[1 - #1] (-2 + 2 #1) &, 0.199709902553977194585}] ||
x == Root[{-1 - 2 Log[#1] #1 + Log[1 - #1] (-2 + 2 #1) &, 0.80029009744602280541}]
*)
% // N
(* x == 0.19971 || x == 0.80029 *)

Plot[{1/2, -(1 - x) Log[1 - x] - x*Log[x]}, {x, 0, 1}]


• +1. Why not Solve[-(1 - x) Log[1 - x] - x*Log[x] == 1/2, x, Reals]? Commented Jul 6, 2015 at 20:11
• @MichaelE2 I tend to use Reduce[ ] when you may expect branching issues. You're right in this case, though. Commented Jul 6, 2015 at 20:13