Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following problem from a textbook I am trying to integrate:

enter image description here

So, following the directions in text, I am required to integrate each function. However, I cannot get Mathematica to integrate the first function. Here is my code:

Z1 := E^-x^2*Cos[x^2 + y^2]
Z2 := 2 - x^2 - y^2
Plot3D[{Z1, Z2}, {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1, ViewPoint -> {4, 1, 1}]
Integrate[Z2, {y, -1, 1}, {x, -1, 1}] - Integrate[Z1, {y, -1, 1}, {x, -1, 1}]

They plot OK:

enter image description here

but give me really strange output:

enter image description here

Could someone please explain how I can overcome this? Wolfram|Alpha can evaluate it without (much) trouble.

Thank you for your time.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Mathematica is giving you an exact symbolic result. If want a numeric integral, you should use NIntegrate instead of Integrate, or just wrap your result in N. If you want, say, 30 significant digits,

N[Integrate[Z2, {y, -1, 1}, {x, -1, 1}] - 
  Integrate[Z1, {y, -1, 1}, {x, -1, 1}], 30]

3.02706907398351331410210839012 + 0.*10^-31 I

share|improve this answer
    
Yep, that was it! Thank you! –  spryno724 Nov 21 '12 at 22:58
add comment

You can use, in principle, Boole inside Integrate like this:

NIntegrate[
 Boole[E^-x^2 Cos[x^2 + y^2] < z < 2 - x^2 - y^2], {x, -1, 1}, {y, -1,
   1}, {z, -1, 3}]

the result is given as 3.0138472, despite warnings NIntegrate::slwcon: and NIntegrate::eincr:

I'm not able to figure out what actually happens at present, but I'm sure this way of using Boole will helps, especially for the integration of irregular regions or volumes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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