I need to define the cost function in the shaped beam synthesis, which is the difference between desired gain and estimated gain within the contour region. I need to know whether the gain has to be defined at the edge of the contour or within the region of the contour. I have defined the cost function where the gains are defined within the contour. While optimizing for a minimum cost function, the program does not converge. Can anyone help me in this?