How can I compute two dimensional integral for the function f[x,y]
, which is multi-valued?
This function appears as follows:
- For a given pair
{x,y}
I solve numerically withNSolve
the equationg[x,y,z]==0
with respect toz
. - Then I compute
f=F[z]
, whereF
can be (for instance)Sqrt
function. So, I deal with functionf
which depends on(x,y)
Naively, I evaluate this integral using integral sum:
- Creatre grid
{x,y}
with spacesdx
&dy
- Then compute
f=f[x,y]
at every point{x_i,y_i}
- Sum all contributions
f[x_i,y_i]
at a given point{x_i,y_i}
- Then sum over grid with weight
dx*dy
This procudure has convergence issues due to complicated structure of f
: the function depends on parameter a
and for differrent values of parameter my computation produce outliers (for instance, the typical value of integral is about 0.5
and for some values of a
the integral value blows up to 32000
). Handling with the function f
, it seems that integral saturates in a very small domain in (x,y)
-space. In addition, the described computation scheme works slow.
About one year ago I have asked the related question and have obtained very detailed answer from MichaelE2. At first glance, it seems good idea. However, when I have implemented the suggested solution the convergence problems appeared: the mentioned function depended on a parameter a
and there were outliers in integral values for different values of parameter a
.
NSolve
search (wouldFindRoot
be a better choice?). Doing a 3D plot of the values could give you an idea of where unreliable values lie. It might be worth do 2D interpolation on these values and then integrating that. Might a log transformation make your function better behaved? (Log before fitting surface, the Exp afterwards) $\endgroup$NSolve
,FindRoot
seems irrelevant because I am interested in roots in the given range, i.e.z1<z<z2
wherez1
&z2
are known constants $\endgroup$