3
$\begingroup$

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}]

enter image description here

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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 $\endgroup$ Commented Aug 26, 2022 at 6:28
  • 1
    $\begingroup$ $p1+p2+p3=1$,and $p1,p2,p3\in [0,1]$ $\endgroup$
    – karry
    Commented Aug 26, 2022 at 6:31

1 Answer 1

7
$\begingroup$
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}}

$\endgroup$
1
  • $\begingroup$ Wait a minute, can I get the exact solution? Or 0.431946 is the exact solution? $\endgroup$
    – karry
    Commented Aug 26, 2022 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.