Plotting a piecewise function with strange subdomains

I have a function, which analityc expression is $C=2*max[b-c,0]$(you can see the expressions of b and c down). Then I have to considerer $q_\pm=\frac{(1\pm \sqrt{ (1-C^2)})}{2}$ and then to plot $E_n=-q_+log_2(q_+)-q_-log_2(q_-)$.

I tried in this way:

b = (p*(2 - n)/4);
c = n*(1 + p)*(2 - n)/16 + (1 - p)*(2 - n)/8;
Conc = If[(b - c) < 0, 0, 2*(b - c)];
qplus = (1 + Sqrt[1 - Conc^2])/2;
qminus = (1 - Sqrt[1 - Conc^2])/2;
En = -qplus*Log[2, qplus] - qminus*Log[2, qminus]
Plot3D[En, {n, 0, 2}, {p, 0, 1}]


This is the output:

-(1/(2 Log[ 2]))(1 - √(1 - If[2 (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) < 0, 0, 2 (b - c)]^2)) Log[ 1/2 (1 - √(1 - If[2 (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) < 0, 0, 2 (b - c)]^2))] + (1/( 2 Log[2]))(-1 - √(1 - If[2 (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) < 0, 0, 2 (b - c)]^2)) Log[ 1/2 (1 + √(1 - If[2 (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) < 0, 0, 2 (b - c)]^2))]

Indeterminate expression (0 (-∞))/Log[2] encountered.

I don't know where is the error. Thank you.

• Does En = N@(-qplus*Log[2, qplus] - qminus*Log[2, qminus]) fix the problem?
– kglr
Sep 3, 2014 at 10:58
• No. There aren't more error segnalations, but there are still the "If" inside the expression and an uncompleted graphic Sep 3, 2014 at 12:03

When $q_\pm=0$, you get $q_\pm\log_2q_\pm=0\cdot(-\infty)$ which is indeterminate. You can define your own function

f[x_] := Piecewise[{{x Log[2, x], x > 0}, {0, x <= 0}}]


and use that instead. By the way, you can also just write Conc = 2 Max[b - c, 0].

b = (p*(2 - n)/4);
c = n*(1 + p)*(2 - n)/16 + (1 - p)*(2 - n)/8;
Conc = 2 Max[b - c, 0];
qplus = (1 + Sqrt[1 - Conc^2])/2;
qminus = (1 - Sqrt[1 - Conc^2])/2;
f[x_] := Piecewise[{{x Log[2, x], x > 0}, {0, x <= 0}}]
En = -f[qplus] - f[qminus]
Plot3D[En, {n, 0, 2}, {p, 0, 1}, PlotRange -> All, Exclusions -> None]


• Perfect, thank you! Sep 5, 2014 at 8:23