Extremum of functional of a complex function consider functional $E$ defined by
$$E[z]=\int F(x,z(x))dx$$
where $F$ is a complex-valued nonlinear function.
How can we find the function $z(x)$ so that
$$G=|E|^2=EE^*=\iint F(x_1,z(x_1))F^*(x_2,z(x_2))dx_1dx_2$$
takes its maximum?
 A: Find $z$ maximizing $$G(z):=\iint_\Omega F\big(x_1,z(x_1)\big) F^*\big(x_2,z(x_2)\big) \,dx_1 \,dx_2$$
We are given $F$ -- I assume it is twice differentiable, but there are methods (mentioned below) in nonlinear optimization that work for functions which are not.  I assume there are no restrictions on $z$; if it must be continuous you will select a different numerical approximation.  I assume $\Omega$ to be the box $[a,b]\times[a,b]\in\mathbb{R}^2$.
Let $z$ be a map from $\mathbb{R}\to\mathbb{C}$.  Pick a discretization for $x$ of size $n$, e.g., divide $[a,b]$ into $n$ segments of equal length.  Their length will be $\ell=\frac{b-a}{n}$ so that their center points are $x_{k}=a+(k-\frac{1}{2})\ell$.  We approximate the integral by the midpoint rule -- there are vastly better methods but this is suitable for a first attempt.  This gives us the approximation
$$G_n(z)=\ell^2\sum_{j=1}^n\sum_{k=1}^n F\big(x_j,z(x_j)\big)F^*\big(x_k,z(x_k)\big)$$
We now pick a discretized approximation to $z$ by defining (where $i=\sqrt{-1}$): $$z_k=a_k+i b_k=z(x_k)$$ and assuming $z$ is constant on the whole interval of length $\ell$ surrounding $x_k$.  Now $z$ is just a sequence of complex values and we have
$$G_n(z)=\ell^2\sum_{j=1}^n\sum_{k=1}^n F\big(x_j,a_j+ib_j\big)F^*\big(x_k,a_k+ib_k\big).$$
Our goal is to pick the values of $a_k$ and $b_k$ for each $k\in\{1,2,\dotsc,n\}$ maximizing $G_n$.
There are a wide variety of nonlinear techniques to solve this unconstrained problem -- Newton's method ought to work well if you have two derivatives and a reasonable initial guess.  Your goal is to find the stationary points where the derivative is zero, and check they are a maximum by looking at the second derivative.  If you don't have derivatives then you can use something like the compass method.
And for what it's worth, in my opinion the hardest part will be correctly writing the derivatives of the function.
