0
$\begingroup$

I would like some help trying to use Mathematica (I just started using it!) to compute the numerical integration of a complicated function (assigned "longitudinalWake" in this example). Essentially, I have a single function of several variables (this example 4 variables: s, sprime, d, and x0) and I would like to integrate over each variable, in a specific order, numerically. My first method is a bit brute-force style by just nesting the NIntegrate operations one after another. I also tried, as a member as mentioned before, to compute the integration using a single NIntegrate operation. Both methods give me back errors. Any help would be greatly appreciated as I think I have exhausted the mathematica manual!

lq = 0.1;
kq = 2;
rho = 1/(kq*x0);
b = 1 - 1/(2 gamma^2);
gamma = 1000/0.511;
c = 3*10^8;
e = 1.60217733*10^-19;
rc = 2.81794092*10^-15;

longitudinalWake=(4.31990343036`*^-10 x0^2 (-1.` + 2.` x0^2 + 
 Cos[2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(
   1/3)]) ((-0.1` - 1.` d) x0 Cos[
   2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)] + (-0.5` + 
    x0^2) Sin[
   2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)] + 
 0.9999998694395` x0 \[Sqrt](-0.99` + 0.2` d + d^2 + 0.5`/x0^2 + 
     x0^2 + ((-0.5` + x0^2) Cos[
       2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)])/
     x0^2 + ((-0.1` - 1.` d) Sin[
       2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)])/x0) + 
 0.5` Sin[
   2 2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(
    1/3)]))/((-0.1` - 1.` d) x0 Cos[
 2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)] + (-0.5` + 
  1.` x0^2) Sin[
 2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)] + 
   1.000000130560517` x0 \[Sqrt](-0.99` + 0.2` d + d^2 + 0.5`/x0^2 + 
   x0^2 + ((-0.5` + x0^2) Cos[
     2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)])/
   x0^2 + ((-0.1` - 1.` d) Sin[
     2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)])/x0) + 
   0.5` Sin[2 2^(2/3) 3^(1/3) (-s + sprime)^(1/3) Abs[x0]^(1/3)])^3



SumOverSprime[s_, x0_, d_] := NIntegrate[longitudinalWake*(10^-10/10^-5), {sprime, 0, 10^-5}]

SumOverx0[s_, d_] := 2 NIntegrate[SumOverSprime[s, x0, d], {x0, 0, 10^-5}]

SumOverd[s_] := NIntegrate[SumOverx0[s, d], {d, 0, 1}]

Erms = Sqrt[(NIntegrate[(SumOverd[s])^2, {s, 0, 10^-5}]) - (NIntegrate[(SumOverd[s]), {s, 0, 10^-5}])^2]
$\endgroup$
  • $\begingroup$ What do the errors say? We can't read your computer screen :) $\endgroup$ – Marius Ladegård Meyer Jun 26 '17 at 10:12
  • $\begingroup$ First thought: you definitely should use a single NIntegrate command, and since none of the integration limits depend on other variables, the "order in which you integrate" does not matter. $\endgroup$ – Marius Ladegård Meyer Jun 26 '17 at 10:14
  • $\begingroup$ make longitudanlwake explicitly a function of its variables longitudinalWake[x0_, s_, sprime_] = (thats a plain = not := ). Then make sure longitudinalWake[x0, s, sprime] with reasonable numeric arguments evaluates to a numeric value. (Your post has syntax error related to Sqrt but that might be an issue with the post here. ) $\endgroup$ – george2079 Jun 26 '17 at 14:49
  • $\begingroup$ @george2079 Oh Hmmm, the "Sqrt" syntax error is simply a sqrt sign. I copied and pasted the code into a mathematica worksheet before posting and its pasted as a sqrt sign and worked fine. Im trying you suggestion for the longwake right now! $\endgroup$ – Donkey Kong Jun 26 '17 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.