Finding a maximum of a Bézier function

Suppose I have a Bézier function f:R2→Rf:\mathbb{R}^2\to\mathbb{R} with random coefficients:

coefs = Table[{RandomReal[]}, {i, 0, 3}, {j, 0, 3}];
f = BezierFunction[coefs];

It seems to behave quite well:

Plot3D[f[s, t], {s, 0, 1}, {t, 0, 1}]

Now I would like to find the maximum of ff. However,

NMaxValue[f[s, t], {s, t} ∈ Rectangle[{0, 0}, {1, 1}]]

only prints

What is wrong and how to fix it?

P.S.: Of course, I could implement Bézier function by myself using Bernstein polynomials etc. But since Mathematica provides this BezierFunction construct, I would like to understand it and be able to use it.



1 Answer


The error message tells everything:

“NMaxValue::nnum: “The function value {-0.31322198} is not a number at {s,t} = {0.6524678079740285,0.04524817776440737}””

NMaxValue[First[f[s, t]], {s, t} ∈ Rectangle[{0, 0}, {1, 1}]]