So I want to numerically compute the integral of a long complicated expression over a specified domain (in this case an ellipse). I know how to use a Boole function to sample within the ellipse, but I want to pass a list of points within this ellipse into the function and have the integral be evaluated at each of these specific points. An example would be:

$\frac{1}{(x \cos(\theta)+y \sin(\theta))^\frac{5}{2}} $

So I want to integrate over θ from 0 to 2 π and I want to use different points (x, y) within the specified domain when integrating. Can anyone help me with this?


1 Answer 1


Humm... This integral is zero. So the answer to your question is zero for any x, y

$$\frac{1}{(x \cos(\theta)+y \sin(\theta))^\frac{5}{2}}$$

Clear[theta, x, y];
f = 1/(x Cos[theta] + y Sin[theta])^(5/2);
int = Integrate[f, theta];

int /. theta -> 2 Pi

Mathematica graphics

int /. theta -> 0

Mathematica graphics

(int /. theta -> 2 Pi) - (int /. theta -> 0) 
(* 0  *)


From comment below that the function used was just an example, here is one way to make a function to use NIntegrate for different x,y values. Changed the original function a little bit

ClearAll[theta, x, y, f];
f[{x_?NumericQ, y_?NumericQ}, theta_?NumericQ]:= 1/(x Cos[theta]^2+y Sin[theta])^(5/2);

pts = RandomReal[{0, 1}, {5, 2}];(*10 points*)

int = NIntegrate[Evaluate@f[#, theta], {theta, 0, 2 Pi}] & /@ pts

Mathematica graphics

This is a made up function just for illustration. Replace your actual function by f above. If this still not what is being asked, please feel free to follow up.

  • $\begingroup$ Or divergent... $\endgroup$
    – Michael E2
    Feb 11, 2014 at 4:33
  • $\begingroup$ I'm sorry if I was unclear, but that isn't the actual function. The actual function is honestly too long to type, how did you get mathematica output directly into your post? Once I know that I can just post the result directly $\endgroup$ Feb 11, 2014 at 4:55
  • $\begingroup$ @Nasser Cool, that is helpful. Thank you. So does random real just choose a random set of ten points in your example? What if I want to create a grid of a specified resolution in the plane, and then evaluate the integral at each of these grid points? $\endgroup$ Feb 11, 2014 at 15:19
  • $\begingroup$ Let me comment that the approach depends strongly on the concrete form of the expression to be integrated. The one above, for example, admits passing to a single parameter: (x Sin[t]+y Cos[t])^5/2==x^5/2*(Sin[t]+z*Cos[t])^5/2where z=y/x. If this (or at least, something like this) is the case, the problem becomes especially simple. $\endgroup$ Aug 29, 2014 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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