Selected Problems from
A First Course in Probability by Sheldon Ross

Problem 36 (Page 192)

(* 
      our expection for the E[(n^2)] when i = 
        2 is given by *) 
 expectedNSqrI2 = Simplify[
        4 ((p^2) + (q^2)) + 
            9 (2  (p^2) q + 2  (q^2) p) /. {q -> 
              1 - p}]

var = Simplify[expectedNSqrI2 - (((2 + 2 p - 2 (p^2)))^2)]

(* 
      looking for the maximum of this expression *) 
D[var, p] // Simplify

    D[var, {p, 2}] // Simplify