# NIntegrate with variable limit of integration [duplicate]

Hey guys Im working with this integral and I can´t get it right.

f2[x, y] = -(a^2)*NIntegrate[NIntegrate[
p*Exp[-I*p*(2*Pi/lambda)*(a/R)*Sqrt[(x^2 + y^2)]*
Cos[phi - ArcTan[y/x]]], {phi, (alfa0 -
ArcSin[d/(2*a*p)]), (alfa0 + ArcSin[d/(2*a*p)])}], {p, e, 1}]


The error message is

phi = -1. ArcSin[0.000333333/p] is not a valid limit of integration.


Why Mathematica doesnt like this limit of integration? Thanks a lot!

Thanks @george2079 I´ve seen that post before I writed this one and I didnt realize that I needed to put the things like this

i1[p_?NumericQ] := i1[p] = NIntegrate[ Exp[-Ip(2*Pi/lambda)*(a/R)Sqrt[(x^2 + y^2)] Cos[phi - ArcTan[y/x]]], {phi, (alfa0 - ArcSin[d/(2*a*p)]), (alfa0 + ArcSin[d/(2*a*p)])}]

i2[x_?NumericQ, y_?NumericQ] := i2[x, y] = NIntegrate[i1[p], {p, e, 1}]

Thanks to all!

(Dont know how to edit the equations to appear with colors and all that stuff sorry!)

## marked as duplicate by march, user9660, Community♦Oct 16 '15 at 19:40

• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Oct 16 '15 at 18:50
• You have many undefined symbols in your code. NIntegrate requires that all quantities except the integration variables have numerical values. – bbgodfrey Oct 16 '15 at 18:53
• Try this NIntegrate[NIntegrate[phi, {phi, 0, b}], {b, 0, 1}] and read this "If the symbol b in this example does not evaluate to a number, a warning message is generated and the integral is returned unevaluated". Correct use of NIntegrate: NIntegrate[phi, {phi, 0, 1}] – garej Oct 16 '15 at 18:53
• All the variables are defined before that statement in my script except the variables "x and y". The variable "p" in the inner NIntegrate gets evaluated in the outer NIntegrate – Tomas Libutti Oct 16 '15 at 19:01
• – george2079 Oct 16 '15 at 19:04

lambda = 1; a = 5; R = 1; alfa0 = 1; d = 1; e = 0.; (* for testing *)

• @TomasLibutti. Because with the definition of f2[x_,y_] := using :=. The right-hand side doesn't get evaluated until you call f2 with numeric arguments, at which point those values get put in there before it tries to evaluate the integrals. – march Oct 16 '15 at 19:19