Timeline for NIntegrate with a function defined with conditions
Current License: CC BY-SA 4.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 22, 2020 at 19:44 | comment | added | N0va | I addressed the extension to higher dimensions in an edit of the answer.The code in the comment above is valid but to run it in a feasible time one would need to decrease the PrecisionGoal and AccuracyGoal of the NIntegrates involved. The solution presented in the answer circumvents those issues by means of analytic and/or unnested numerical integration. | |
| Oct 22, 2020 at 19:41 | history | edited | N0va | CC BY-SA 4.0 | Adressing the question posed in the comments |
| Oct 22, 2020 at 16:19 | comment | added | TsuKi | area[J_?NumberQ, L1_?NumberQ, L2_?NumberQ] := Block[{int1, int2}, If[L1 < 0, int1 = L1*NIntegrate[Max[J x, x^2], {x, 0, 1}], int1 = L1*NIntegrate[Min[J x, x^2], {x, 0, 1}]]; If[L2 < 0, int2 = L2*NIntegrate[Max[J x^2, x], {x, 0, 1}], int2 = L2*NIntegrate[Min[J x^2, x], {x, 0, 1}]]; Return[Abs[int1 - int2]]] volume[J_?NumberQ] := NIntegrate[area[J, L1, L2], {L1, -1, 1}, {L2, -1, 1}] If I plot the area function it shows the correct plot ContourPlot[area[1, L1, L2], {L1, -1, 1}, {L2, -1, 1} However if I evaluate volume[1] the programm gets stuck. Thanks! | |
| Oct 22, 2020 at 16:17 | comment | added | TsuKi | Dear @N0va: I have tried your code, it works fine and I get the given plot, thank you. If you don't mind a further question, is it possible to extend this code to a two-variable integral? Something like this: | |
| Oct 22, 2020 at 1:13 | history | answered | N0va | CC BY-SA 4.0 |