# NIntegrate::inumr error while integrating interpolated functions

Posted 1 month ago
289 Views
|
2 Replies
|
2 Total Likes
|
 Hello guys, I have a problem with double Integral length = 10*10^-6; dz = 5*10^-7; anzahl = length/dz; z = N[Range[0,length,dz]]; f = Range[anzahl+1]; For[i=1,i<(anzahl+2),i++,f[[i]]=RandomReal[{-3*10^-9,3*10^-9}]]; koordinaten = Transpose[{z, f}]; finterpol = Interpolation[koordinaten]; finterpol2[zn_] := Piecewise[{{0,zn<0},{finterpol[zn],0<=zn<=length},{0,zn>length}}] I use this Piecewise function "finterpol2[zn_]" with an interpolated function in it for the following integration. (beta, n1, n2 and k0 are constants ) Ftilde[theta_] := NIntegrate[finterpol2[zn]*Re[Exp[-I*(beta-(n2*k0*Cos[theta]))*zn]],{zn,-Infinity,Infinity}]; After that I want to do a definite integration with Ftilde ([Phi][d] is defined and outputs a constant): alpha = \[Phi][d]^2*(n2^2-n1^2)^2*(k0^3)/(4*Pi*n1)*NIntegrate[(1/length)*Abs[Ftilde[theta]]^2,{theta,0,Pi}] For the integral which calculates alpha I get an error message:"NIntegrate::inumr: The integrand ([Piecewise] <<1>>) Re[E^(-I zn (1.0924610^7-5.8372810^6 Cos[theta]))] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.,5.*10^-7}}." and so on.How can I solve this?Thank you in advance for all the answers.
2 Replies
Sort By:
Posted 1 month ago
 Andrei,Sorry for the late response! There seem to be two issues with your code: the integrand (under NIntegrate) should evaluate to a numerical value - as the error message suggests; therefore you need to define beta and n2 and k0 before. instead of Ftilde[theta_] := NIntegrate[...] write Ftilde[theta_?NumberQ] := NIntegrate[...]