# Maximize does not work properly

I am trying to use Maximize to find the maximum value of f, which is a polynomial in terms of Sin[t] and Cos[t].

A = {{1, 2}, {2, 3}};
B = {{1, -2}, {-2, 0}};
p = {Cos[t], Sin[t]};
f = (p.A.A.p - (p.A.p)^2)(p.B.B.p - (p.B.p)^2)
Maximize[{f, 0 <= t <= \[Pi]/2}, t]


I thought it should be straightforward. However, the result I get is a very long expression, which does not make sense. I have no idea where I make a mistake.

• Try Maximize[{Simplify@f, 0 <= t <= \[Pi]/2}, t] // N. Commented Sep 7, 2020 at 0:54

\$Version

"12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)"

Clear["Global*"]

A = {{1, 2}, {2, 3}};
B = {{1, -2}, {-2, 0}};
p = {Cos[t], Sin[t]};


FullSimplify prior to finding the maximum

f = (p.A.A.p - (p.A.p)^2) (p.B.B.p - (p.B.p)^2) // FullSimplify

(* 1/16 (9 + 7 Cos[4 t] + 6 Sin[4 t])^2 *)


FullSimplify after finding the maximum

{max, arg} = Maximize[{f, 0 <= t <= π/2}, t] // FullSimplify

(* {1/8 (83 + 9 Sqrt[85]), {t -> 1/2 ArcTan[1/6 (-7 + Sqrt[85])]}} *)


The approximate numeric values are

{max, arg} // N

(* {20.747, {t -> 0.177157}} *)


Visually,

Plot[f, {t, 0, π/2}, Epilog ->
{Red, AbsolutePointSize[4], Point[{t, f} /. arg]}]
`