0
$\begingroup$

This question already has an answer here:

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!)

$\endgroup$

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ 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. $\endgroup$ – bbgodfrey Oct 16 '15 at 18:50
  • $\begingroup$ You have many undefined symbols in your code. NIntegrate requires that all quantities except the integration variables have numerical values. $\endgroup$ – bbgodfrey Oct 16 '15 at 18:53
  • $\begingroup$ 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}] $\endgroup$ – garej Oct 16 '15 at 18:53
  • $\begingroup$ 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 $\endgroup$ – Tomas Libutti Oct 16 '15 at 19:01
  • 3
    $\begingroup$ duplicate: mathematica.stackexchange.com/q/10533/2079 $\endgroup$ – george2079 Oct 16 '15 at 19:04
2
$\begingroup$

I believe this is a duplicate of the question linked in the comments. Here is the syntax:

lambda = 1; a = 5; R = 1; alfa0 = 1; d = 1; e = 0.; (* for testing *)
g[p_?NumericQ, x_, y_] := 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)])}]
f2[x_, y_] := -(a^2)*NIntegrate[g[p, x, y], {p, e, 1}]
$\endgroup$
  • $\begingroup$ Thanks a lot! Im just starting with this and I was not aware of the ?NumericQ functionality. $\endgroup$ – Tomas Libutti Oct 16 '15 at 19:12
  • $\begingroup$ @TomasLibutti. Yeah: it's a common problem new (and not so new: I used Mathematica for a long time before I ran across this solution) users have! It is common enough that there is a post about it on the pitfalls thread. $\endgroup$ – march Oct 16 '15 at 19:15
  • $\begingroup$ Just to know a little bit more. Why in g[p_?NumericQ,x_,y_] the variables x and y doesnt have the ?NumericQ statement? Thanks! $\endgroup$ – Tomas Libutti Oct 16 '15 at 19:17
  • $\begingroup$ @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. $\endgroup$ – march Oct 16 '15 at 19:19

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