# How can I find the maximal value of this?

I already plot the image of the function S:

(* structural entropy for N=3 *)
S[p1_, p2_] := (
S1 = -(p1*Log[p1] + p2*Log[p2] + (1 - p1 - p2) Log[(1 - p1 - p2)]);
S2 = 1 - (p1^2 + p2^2 + (1 - p1 - p2)^2);
Sstr = S1 - S2
)
Plot3D[S[p1, p2], {p1, 0, 1}, {p2, 0, 1}]


I use the code

MaxValue[{S[p1, p2], 0 <= p1 <= 1, 0 <= p2 <= 1}, {p1, p2}]


but I can't get the maximum value. The output can give the answer.

• Look at "S1" If p1+p2==1, "S1" is not defined. If p1+p2>1, "S1" is complex. Therefore, there is no max. for 0<= {p1,p2}<=1 Aug 26, 2022 at 6:28
• $p1+p2+p3=1$,and $p1,p2,p3\in [0,1]$ Aug 26, 2022 at 6:31

sol = Solve[{Grad[S[p1, p2], {p1, p2}] == 0, 0 < p1 <= 1, 0 < p2 <= 1,
1 - p1 - p2 > 0}, {p1, p2}]
S[p1, p2] /. sol[[1]]
% // N
hessian = D[S[p1, p2], {{p1, p2}, 2}] /. sol[[1]]
NegativeDefiniteMatrixQ[hessian]


{p1 -> 1/3, p2 -> 1/3}

-(2/3) + Log[3]

0.431946

True

The same as

NMaximize[{S[p1,p2],
0 < p1 <= 1, 0 < p2 <= 1, 1 - p1 - p2 > 0}, {p1, p2}]


{0.431946, {p1 -> 0.333197, p2 -> 0.333294}}

• Wait a minute, can I get the exact solution? Or 0.431946 is the exact solution? Aug 26, 2022 at 6:38