Definition of the function g:
f2[x_] := (x*(FresnelC[x] + FresnelS[x]) + (Cos[Pi*x^2/2] -
Sin[Pi*x^2/2])/Pi)/2
g[x1_, x2_, y1_, y2_] :=
2*(f2[x2 - y1] - f2[x1 - y1] - f2[x2 - y2] + f2[x1 - y2])/(x2 - x1 +
y2 - y1)
First maximization with a suitable domain:
NMaximize[{g[x1, x2, y1, y2], 0 < x1 < x2 < 7 && -7 < y1 < y2 < 0}, {x1, x2, y1, y2}]
Out[33]= {0.00937548, {x1 -> 1.60404, x2 -> 5.27857, y1 -> -2.89746,
y2 -> -0.0330524}}
Second maximization with a smaller domain: why the maximum is larger???
In[34]:= NMaximize[{g[x1, x2, y1, y2], 0 < x1 < x2 < 5 && -5 < y1 < y2 < 0}, {x1, x2, y1, y2}]
Out[34]= {0.0260921, {x1 -> 1.63214, x2 -> 3.49276, y1 -> -1.26015,
y2 -> -0.0177181}}