I am trying to adapt the following piece of code (coming from this answer):
Clear@int
int[expr_, {var_, 0, rlst_List}] := int[expr, {var, 0, #}] & /@ rlst
int[expr_, {var_, 0, r_?NumericQ}] := With[{pos = Rescale[r, domain, {1, points}]}, trap[Function @@ {var, expr}, grid[[;; pos]]]]
to my real case in which I have three variables, but I get the error
Iteration limit of 4096 exceeded.
I have tried to mess around with the code but I could not find a solution. Here is what I have now:
Clear@int
int[expr_, {var_, -81/100, rlst_List}, {var2_, 1/10, \[Theta]lst_List}, {var3_, 0, [Phi]lst_List}] := int[expr, {var, -81/100, #1}, {var2, 1/10, #2}, {var3, 0, #3}] & @@ {rlst, \[Theta]lst, \[Phi]lst}
int[expr_, {var_, -81/100, r_?NumericQ}, {var2_, 1/10, \[Theta]_?NumericQ}, {var3_, 0, \[Phi]_?NumericQ}] := With[{pos1 = Rescale[r, domain1, {1, points}], pos2 = Rescale[\[Theta], domain2, {1, points}], pos3 = Rescale[\[Phi], domain3, {1, points}]}, trap[Function @@ {var, var2, var3, expr}, grid1[[;; pos1]], grid2[[;; pos2]], grid3[[;; pos3]]]]
trap calculates an integral with the trapeziodal rule, tell me if you need that piece of code too.
EDIT I haven't tried the suggestion by @flinty, but I tried to use smaller lists, down to just one element, but the problem remains, so I think that there is actually some issue with the code.
EDIT2 I have now tried to set $IterationLimit to $10^6$ but I still get the error
EDIT3 Now that I think of it, the original code Maps the list into int, this is what I should do in my modified version, not Apply: I have to redefine the function int from scratch I think...
EDIT4 I think I have a solution, probably not the best one, but a solution:
int2[r_Real, \[Theta]_Real, \[Phi]_Real] := int2[r, \[Theta], \[Phi]];
int2[r_, \[Theta]_, \[Phi]_] := int[r1^2, {r1, -81/100, r}, \[Theta]1, 1/10, \[Theta]}, {\[Phi]1, 0, \[Phi]}];
MapThread[int2, {grid1, grid2, grid3}]
It gives as output a list like the original one. The problem is that I have to define many int one for each integrated function, but that can be done easily....
$IterationLimit? – flinty May 26 '21 at 11:03int[expr, {var, -81/100, #1}, {var2, 1/10, #2}, {var3, 0, #3}] & @@ {rlst, \[Theta]lst, \[Phi]lst}is wrong, think carefully about what I am doing with theMapin my original implementation, you should never modify code blindly. – xzczd May 26 '21 at 14:30inttakes in inputRealsnot lists and it works on numbers from the grids, now I have to find a way toMapThreador something the lists... – mattiav27 May 26 '21 at 14:37