How can I compute two dimensional integral for the function f[x,y], which is multi-valued?

This function appears as follows:

  1. For a given pair {x,y} I solve numerically with NSolve the equation g[x,y,z]==0 with respect to z.
  2. Then I compute f=F[z], where F can be (for instance) Sqrt function. So, I deal with function f which depends on (x,y)

Naively, I evaluate this integral using integral sum:

  1. Creatre grid {x,y} with spaces dx & dy
  2. Then compute f=f[x,y] at every point {x_i,y_i}
  3. Sum all contributions f[x_i,y_i] at a given point {x_i,y_i}
  4. 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.

  • $\begingroup$ I would compute the values on a grid (as you do). If the function varies relatively slowly, there might be some advantages in using a neighouring value to start the NSolve search (would FindRoot 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$
    – mikado
    Jun 6 at 13:12
  • $\begingroup$ @mikado thank you for ideas! Currently I use NSolve, FindRoot seems irrelevant because I am interested in roots in the given range, i.e. z1<z<z2 where z1 & z2 are known constants $\endgroup$ Jun 6 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.