1

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

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Tomas Libutti
  • 51
  • 1
  • 7
  • 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
  • @Tomas Libutti, that is the problem, p should be a number. – garej Oct 16 '15 at 19:03
  • Yep, and the fact that p is not defined is exactly the problem, because that inner NIntegrate requires both an integrand that evaluates to a number and limits that evaluate to a number. There are ways around this: defining the inner Nintegrate using a function g[p_?NumericQ] might work. But pay attention to the other comments. – march Oct 16 '15 at 19:04
  • 3
    duplicate: http://mathematica.stackexchange.com/q/10533/2079 – george2079 Oct 16 '15 at 19:04
  • @garej thanks for the reply but I cant assign a number to ¨p¨ because is the variable of the outer NIntegrate. Sory if I dont get what you are saying Im new in Mathematica – Tomas Libutti Oct 16 '15 at 19:05
  • @march tried that get the same message – Tomas Libutti Oct 16 '15 at 19:06

1 Answers1

2

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}]
march
  • 23,399
  • 2
  • 44
  • 100
  • Thanks a lot! Im just starting with this and I was not aware of the ?NumericQ functionality. – Tomas Libutti Oct 16 '15 at 19:12
  • @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. – march Oct 16 '15 at 19:15
  • 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! – Tomas Libutti Oct 16 '15 at 19:17
  • @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