1
$\begingroup$
f[x_, y_] := 2*x - y

Plot3D[f[x, y], {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}, {y, -2, 2}]

NIntegrate[f[x, y], {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}, {y, -2, 2}]

I get a

Plot3D::plln: Limiting Value -Sqrt[4-y^2] in {x,-Sqrt[4-y^2],Sqrt[4-y^2]} is not a machine-sized real number.

And a

NIntegrate::nlim:x=-Sqrt[4-y^2] is not a valid limit of integration.

I get these same errors with the limits of x: 3*y, 3 and 2-y, 2*y-1 (in different problems).

What is causing this? Is this a bug?

$\endgroup$
  • $\begingroup$ Reverse the limits Plot3D[f[x, y], {y, -2, 2}, {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}] $\endgroup$ – Dr. belisarius Oct 14 '14 at 0:26
  • $\begingroup$ The integral can be done symbolically: Integrate[f[x, y], {y, -2, 2}, {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}] gives 0 $\endgroup$ – Bob Hanlon Oct 14 '14 at 4:23
  • $\begingroup$ Indeed, Integrate[2*x - y, {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}, {y, -2, 2}] gives 0 , while NIntegrate with the same content returns an error meaasge on my machine Win7 Mma10.0. It looks like a bug for me. $\endgroup$ – Alexei Boulbitch Oct 14 '14 at 10:33
  • 1
    $\begingroup$ Why would it be a bug? The iterated integral takes the outermost range first, and while Integrate can handle a symbolic y, NIntegrate (and Plot3D) cannot. $\endgroup$ – ilian May 26 '15 at 19:28
  • $\begingroup$ not a bug, but it is a deficiency in the Plot3D docs that fail to mention that order matters if the range of one variable depends on the value of another. $\endgroup$ – george2079 May 26 '15 at 20:17
2
$\begingroup$

While belisarius's comment answers the question, an arguably better way to achieve these is to use regions. For example, the plot is less choppy and there is less rounding error when integrating (for this example at least).

(* without regions *)
f[x_, y_] := 2*x - y

(* choppy plot *)
Plot3D[f[x, y], {y, -2, 2}, {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}]

enter image description here

(* messages thrown *)
NIntegrate[f[x, y], {y, -2, 2}, {x, -1*Sqrt[4 - y^2], Sqrt[4 - y^2]}]
During evaluation of NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

During evaluation of NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained -1.16877*10^-16 and 7.359246377230905`*^-16 for the integral and error estimates. >>

-1.16877*10^-16
(* with regions *)
f[x_, y_] := 2*x - y

(* less choppy *)
Plot3D[f[x, y], {x, y} ∈ Disk[{0, 0}, 2]]

enter image description here

(* no rounding error *)
NIntegrate[f[x, y], {x, y} ∈ Disk[{0, 0}, 2]]
0.
$\endgroup$
  • $\begingroup$ …tho, since the region of interest is a disk, an appropriate change of coordinates is likely to yield a more expedient and efficient solution. $\endgroup$ – J. M. is away May 27 '15 at 6:33
2
$\begingroup$

Just to illustrate versatility of Mathematica:

Plot3D[2 x - y, {x, -2, 2}, {y, -2, 2}, 
 RegionFunction -> Function[{x, y, z}, x^2 + y^2 < 4]]
f = TransformedField["Cartesian" -> "Polar", 
   2 x - y, {x, y} -> {r, t}];
j = Simplify[Det[Outer[D[#1, #2] &, {r Cos[t], r Sin[t]}, {r, t}]]];
Integrate[f j, {r, 0, 2}, {t, 0, 2 Pi}]

where the plot uses RegionFunction, f transforms plane into polar coordinates, j is Jacobian.

$\endgroup$

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.