2
$\begingroup$

Spected integral

I want to obtain the volume of a function with a double integral. To solve this problem y have to evaluate in respect to x +-sqrt(y-y^2) but when I try to substitute I get this error:

Error:

Sqrt[y - y^2] is not a valid limit of integration

NIntegrate[func1, {x, -Sqrt[y - y^2], Sqrt[y - y^2]}, {y, 0, 1}]

Sqrt[y - y^2] is not a valid limit of integration

NIntegrate[func2, {x, -Sqrt[y - y^2], Sqrt[y - y^2]}, {y, 0, 1}]

My code:

func1 = 1 - y^2 - x^2

func2 = 1 - y

NIntegrate[func1, {x, -Sqrt[y - y^2], Sqrt[y - y^2]}, {y, 0, 1}]

NIntegrate[func2, {x, -Sqrt[y - y^2], Sqrt[y - y^2]}, {y, 0, 1}]

NIntegrate Is the only way I find to solve a double Integral and get a numerical number, yet I can’t use those limits

Is there a way to get around this error?

$\endgroup$
3
  • 1
    $\begingroup$ Outermost limits of a multiple integral should come first in NIntegrate[], per the docs. NIntegrate[1 - x^2 - y^2, {y, 0, 1}, {x, -Sqrt[y - y^2], Sqrt[y - y^2]}] (Compare this with the more natural specification NIntegrate[1 - x^2 - y^2, {x, y} ∈ Disk[{0, 1/2}, 1/2]].) $\endgroup$ – J. M.'s torpor Apr 18 '20 at 7:07
  • $\begingroup$ This is not an error, but a feature. NIntegrate can only provide a numerical result if the integrand is a numerical function (it is here), and likewise are the limits of integration (they are not). $\endgroup$ – yarchik Apr 18 '20 at 7:08
  • $\begingroup$ J. M., your solution also worked. Thanks $\endgroup$ – alejandro.javier Apr 18 '20 at 7:25
2
$\begingroup$

I do not know why you are using NIntegrate since the limit for inner integral is symbolic.

ClearAll[y, x];
Integrate[
  Integrate[(1 - x^2 - y^2), {x, -Sqrt[y - y^2], Sqrt[y - y^2]}], {y, 0, 1}]

Mathematica graphics

  N[%]
  (*0.490874*)

NIntegrate Is the only way I find to solve a double Integral

Sorry, I do not understand the above. Why? Integrate does work.

$\endgroup$
3
  • 1
    $\begingroup$ There is no need to call Integrate[] twice if you follow Mathematica's convention for multiple integrals: Integrate[1 - x^2 - y^2, {y, 0, 1}, {x, -Sqrt[y - y^2], Sqrt[y - y^2]}] $\endgroup$ – J. M.'s torpor Apr 18 '20 at 7:19
  • 1
    $\begingroup$ @J.M. I know that. But because I do not want to worry about the correct order, I always do it this way. By writing explicit double integrals. For me, it is more clear and I do not have to guess (I fell into the order trap before many times. There are many questions on this on this site by users confused on result they obtained that way). It is also how I would do it by hand. So for me, it is just more clear, even thought it is not as short to write. $\endgroup$ – Nasser Apr 18 '20 at 7:28
  • 1
    $\begingroup$ Learning a lot thanks $\endgroup$ – alejandro.javier Apr 18 '20 at 7:28

Your Answer

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

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