I have a function f which looks similar to this :
f[a_, b_, c_] := NIntegrate[sigma[a, b, c], {a, -valueA, valueA}, {b, -valueB, valueB}, {c, -valueC, valueC}]
and wish to integrate it only for valuesa, b, c
where another function g fulfills a certain condition : g[a,b,c] >= threshold
.
I did try using a boolean in this way:
f[a_, b_, c_] := NIntegrate[Boole[g[a, b, c] >= threshold]*sigma[a, b, c], {a, -valueA, valueA}, {b, -valueB, valueB}, {c, -valueC, valueC}]
but I do not get the desired result.
I have also tried to define a Piecewise
function for g this way and include it in the integral instead of the Boole:
Piecewise[{{g[a,b,c] , g[a,b,c]>= threshold}}]
However, I'm afraid that when using the Piecewise
it gets integrated as well, which is not what I wish for. This is just a basic example and in reality I need to pass at least 3 different conditions before I integrate. Looking forward for any tips and help, it's gonna be much appreciated.
tl;dr Trying to numerically integrate a multidmensional integral, and only pass certain values for the variables where conditions a-priori to the integration are fulfilled.
Here's the full integral with prerequisites and values:
(*Transferred energy*)
Tmaxc12[vx_, vy_, vz_, U_, phi_, theta_] :=
0.5*MC12 (vx^2. + vy^2. + vz^2.) + (1 -
Cos[theta])*(Sqrt[Te[U]*(Te[U] + 2 m*c^2)/c^2] + MC12*vz)*
Sqrt[Te[U]*(Te[U] + 2 m*c^2)/c^2]/MC12 -
Sqrt[Te[U]*(Te[U] + 2 m*c^2)/c^2]*
Sin[theta]*(vx*Cos[phi] + vy*Sin[phi])
(*CONSTANTS DEFINITION*)
Te[U_?NumericQ] := U*e;
\[Beta][U_?NumericQ] := Sqrt[1. - 1./((U/m1) + 1.)^2.];
pe[U_] := Sqrt[Te[U]*(Te[U] + 2.*m*c^2.)/c^2.];
c = 299792458.; (*speed of light*)
m = 9.10938356*10^(-31.);
m1 = 510998.;(*electron mass in eV*)
MC12 = 12.011*1.660539040*10^(-27.);
e = 1.60217662*10^(-19.); (*elementary charge*)
\[HBar] =
1.054571800*10^(-34.); (*reduced Planck constant*)
Zc12 = 6.;
eps = 8.85418*10^(-12. );(*vacuum permittivity*)
(*Velocity \
distributions*)
Pvel[v_?NumericQ, Vfit_?NumericQ] :=
1./Sqrt[2.*Pi*Vfit]*Exp[-v^2./(2.*Vfit)]
(*mean squared velocities for C12*)
VfitxyC12 = 1146080.;
VfitxC12 = VfitxyC12/2.; VfityC12 = VfitxyC12/2.; VfitzC12 = 317000.;
vxvalC12 = Sqrt[VfitxC12]; vyvalC12 = Sqrt[VfityC12]; vzvalC12 =
Sqrt[VfitzC12];
(*cross section*)
k1C12 = ((Zc12 e^2.)/(4. \[Pi] eps 2. m c^2.))^2.;
k2C12 = \[Pi] Zc12 e^2. /(\[HBar] c);
sigmaC12[theta_, U_] :=
k1C12* (1. - \[Beta][U]^2.) /\[Beta][
U]^4.*(Csc[theta/2.])^4.*(1. - \[Beta][U]^2.*Sin[theta/2.]^2. +
k2C12*\[Beta][U]*Sin[theta/2.] (1. - Sin[theta/2.]))*10.^28.;
This is how I defined my region of interest, where Tmax>= 21.14:
region = ImplicitRegion[
Tmaxc12[vx, vy, vz, U, phi, theta]/e >=
21.14, {{vx, -vxvalC12, vxvalC12}, {vy, -vyvalC12,
vyvalC12}, {vz, -vzvalC12, vzvalC12}, {phi, 0, 2 Pi}, {theta, 0,
Pi}}];
and now the integral I was trying to solve :
sigma5D[U_] :=
NIntegrate[
sigmaC12[theta, U]*Sin[theta]*Pvel[vx, VfitxC12]*Pvel[vy, VfityC12]*
Pvel[vz, VfitzC12], {vx, vy, vz, theta, phi} \[Element] region,
Method -> "GlobalAdaptive"]
sigma5D[100000] // Timing
error msg:
The region given at position 1 in DiscretizeRegion[ImplicitRegion[...]] is in dimension 5. DiscretizeRegion only supports dimensions 1 through 3.
after which mathematica crashes and quits the kernel.
reg = ImplicitRegion[g[a, b, c] >= threshold, {a, b, c}]
then integrate over that?NIntegrate[sigma[a, b, c], {a, b, c} ∈ reg]
$\endgroup$ImplicitRegion
method. However i get the following error message, because it is by default trying to discretize the region :DiscretizeRegion[ Implicitregion[...]] is in dimension 5. DiscretizeRegion only supports dimensions 1 through 3
. Any thoughts on how I could bypass this error? The example I referred to is in 3D but I am trying to compute a 5D integral. $\endgroup$