Selected Problems from
A First Course in Probability by Sheldon Ross

Problem 22 (Page 190)

expectedI2 = 
      Simplify[2 ((p^2) + (q^2)) + 
            6 ((p^2) q + (q^2) p) /. {q -> 
              1 - p}]

(* 
      looking for the maximum of this expression *) 
D[expectedI2, p]

    D[expectedI2, {p, 2}]

Simplify[
      (p^3) + 3 q (p^3) + 6 (q^2) (p^3) + (q^3) + 3 p (q^3) + 
          6 (p^2) (q^3) /. {q -> 1 - p}]

expectedI3 = 
      Simplify[3 ((p^3) + (q^3)) + 4 (3 q (p^3) + 3 p (q^3)) + 
            5 (6 (q^2) (p^3) + 6 (p^2) (q^3)) /. {q -> 
              1 - p}]

(* 
      looking for the maximum of this expression *) 
rts = 
      Solve[D[expectedI3, p] == 0, p]

    D[expectedI3, {p, 2}] /. rts // Simplify