Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

After a long time developing some code in mathematica and finally getting it to work, I have unfortunately encountered an odd problem: When I change the limits of integration (and shift the function that I am integrating) NIntegrate takes extremely long (on the order of hours) to complete. Now, this would be understandable if I increased the limits of integration but in my case, its the opposite I am decreasing the limits of integration.

Given the following constants and functions:

sL[phi_] := (r*phi^3)/24
lambdaB[z_] := 1/(sigmaSbeg*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSbeg^2))]
lambdaE[z_] := 1/(sigmaSend*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSend^2))]
lambdaC[z_, phi_] := 
 1/(((sigmaSend - sigmaSbeg)/theta *phi + sigmaSbeg)*Sqrt[2 Pi])Exp[-(z^2/(
    2*((sigmaSend - sigmaSbeg)/theta *phi + sigmaSbeg)^2))]    
deEntrance[s_, phi_?NumericQ] := 
 With[{sL = sL[phi]}, 
   ((lambdaC[s - sL, phi] - lambdaB[s - 4 sL])/sL^(1/3) + 
     NIntegrate[(1/(s - sprime)^(1/3)*
        D[lambdaC[sprime, phi], sprime]), {sprime, s - sL, 
       s}])]
deEntranceRMS[phi_?NumericQ] := 
 Sqrt[NIntegrate[
    lambdaE[s]*(deEntrance[s, phi])^2, {s, -5 sigmaSend, 
     5 sigmaSend}] - (NIntegrate[
     lambdaE[s]*(deEntrance[s, phi]), {s, -5 sigmaSend, 
      5 sigmaSend}])^2]

NIntegrate[(eta1[r*phi])*deEntranceRMS[phi], {phi, 0.0,theta}]
NIntegrate[(eta2[r*phi])*deEntranceRMS[phi], {phi, 0.0, theta}]

The following works well and outputs an answer within a reasonable amount of time:

sigmaSbeg = 2.759153*10^-004;
sigmaSend = 2.774392*10^-004;
theta=0.06;
r=9.15445;
eta1[s_]:=-0.05461846 s^2
eta2[s_]:=-0.10923649 s

But, for the following, Mathematica takes extraordinarily long.

sigmaSbeg = 8.280940*10^-006;
sigmaSend = 8.308940*10^-006;
theta=0.014;
r=17.857143;
eta1[s_]:=0.00059452375 + 0.028 (-0.25 + s)^2
eta2[s_]:=-0.014 + 0.056 s

I cannot figure out why. I assume my eta1 and eta2 functions are a little more complex, but they're only shifted quadratics and linear functions. Any help would be great

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.