1
$\begingroup$

Can I use multiple methods for a numerical integration? e.g. I have a 4 dimension integral and for each variable i want to use a different method.

NIntegrate[
  f[x,y,w,z], 
  {x,0,2*Pi}, {y,2,10}, {w, Pi/2, 32*Pi},{z,0,1},
  Method->{...}, Method{..},.]

For each Method i want to use different values of MinRecursion, MaxRecursion.

I hope someone can help me out

$\endgroup$
3
  • 2
    $\begingroup$ You can programmatically implement MinRecursion on an axis with Evaluate[{t, Subdivide[a, b, 2^mr]}], where a and b are the (numerical) limits on the interval for t and mr is a nonnegative integer representing the level of recursion. I don't think you can specify individual values for MaxRecursion, except maybe by writing a custom integration method. -- That said, a cartesian product of four one-dimensional integration methods will usually be very expensive. $\endgroup$
    – Michael E2
    Mar 5, 2021 at 13:27
  • $\begingroup$ What problem do you have with the current result using a single method? There may be a solution to the underlying problem that doesn't require setting individual methods. $\endgroup$
    – MarcoB
    Mar 5, 2021 at 13:46
  • 2
    $\begingroup$ NeAr, may I suggest that you consider revisiting your 15 questions and accepting answers that you think are best. $\endgroup$
    – kglr
    Mar 7, 2021 at 20:20

1 Answer 1

4
$\begingroup$

Can I use multiple methods for a numerical integration?

If you mean different integration rules, then with NIntegrate you can use Method with Cartesian rule specification:

Clear[f];
f[x_, y_, w_, z_] := x + y + w + z;

NIntegrate[
 f[x, y, w, z],
 {x, 0, 2*Pi},
 {y, 2, 10},
 {w, Pi/2, 32*Pi},
 {z, 0, 1},
 Method -> 
   {{"GaussKronrodRule", "Points" -> 12}, 
    {"ClenshawCurtisRule", "Points" -> 3}, 
    {"TrapezoidalRule", "Points" -> 5}, 
    {"TrapezoidalRule", "Points" -> 8}},
 MaxRecursion -> 2]

(* 301901. *)

If you want to use different integration strategies per axis, with you have to use NIntegrate's plug-in framework. See How to implement custom NIntegrate integration strategies? .


For each Method i want to use different values of MinRecursion, MaxRecursion.

Instead of specifying MinRecursion per axis we can use the range specifications (to the same effect):

NIntegrate[
 f[x, y, w, z],
 {x, 0, Sequence @@ 
   Rescale[Range[0, 1, 0.1][[2 ;; -2]], {0, 1}, {0, 2*Pi}], 2*Pi},
 {y, 2, Sequence @@ 
   Rescale[Range[0, 1, 0.25][[2 ;; -2]], {0, 1}, {2, 10}], 10},
 {w, Pi/2, 
  Sequence @@ 
   Rescale[Range[0, 1, 0.25][[2 ;; -2]], {0, 1}, {Pi/2, 32*Pi}], 32*Pi},
 {z, 0, Sequence @@ Range[0, 1, 0.1][[2 ;; -2]], 1},
 Method -> 
   {{"GaussKronrodRule", "Points" -> 3}, 
    {"ClenshawCurtisRule", "Points" -> 3}, 
    {"TrapezoidalRule", "Points" -> 5}, 
    {"TrapezoidalRule", "Points" -> 4}},
 MaxRecursion -> 2]

(* 301901. *)

  • Specifying max recursion per axis with the standard NIntegrate methods is not implemented.

    • I would say such feature would be similar to having MaxPoints specifications per axis.

    • I do not think, though, that those features are needed that much. Just, nice to have and low in the priority list.

  • If different integration strategies per axis are implemented (as mentioned above),then, of course, different axes can have different MaxRecursion values.


As @MichaelE2 pointed out in a comment, using Cartesian product rules for multi-dimensional integrals can be computationally expensive. (Even more so, if coupled with large "min recursion" partitioning of the integration domain.)

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.