# numerical integration – Double NIntegrate

The functions I have are

``````i(d_,(Tau)_,g_,w_)=-FractionBox("1", "8") (-1+SqrtBox(RowBox({"1", "-", SuperscriptBox("d", "2")}))) (2 SuperscriptBox("g", "2")+SuperscriptBox("w", "2")-SuperscriptBox("w", "2") Cos(2g*(Tau)))

a((Tau)_,g_,d_)=ArcCos(FractionBox("1", "4") SqrtBox(RowBox({"1", "-", "d"})) (SqrtBox(RowBox({"1", "-", "d"}))+SqrtBox(RowBox({"1", "+", "d"}))+(SqrtBox(RowBox({"1", "-", "d"}))-SqrtBox(RowBox({"1", "+", "d"}))) Cos(g *(Tau)))+FractionBox("1", "4") SqrtBox(RowBox({"1", "+", "d"})) (SqrtBox(RowBox({"1", "-", "d"}))+SqrtBox(RowBox({"1", "+", "d"}))+(-SqrtBox(RowBox({"1", "-", "d"}))+SqrtBox(RowBox({"1", "+", "d"}))) Cos(g *(Tau))))

b(t_,w_,g_,d_)=Sqrt(-FractionBox("1", "8") (-1+SqrtBox(RowBox({"1", "-", SuperscriptBox("d", "2")}))) (2 SuperscriptBox("g", "2")+SuperscriptBox("w", "2")-SuperscriptBox("w", "2") Cos(2g*t)))

c((Tau)_,w_,g_,d_):=NIntegrate(b(t,w,g,d),{t,0,(Tau)})

e((Tau)_,g_,d_,w_):=a((Tau),g,d)*(Tau)/c((Tau),w,g,d)
``````

Where all parameters except t and g are fixed (tau=4, d=0.5, w=5)

(sorry for the format but if you copy it to Mathematica you get the right functions)

Now as you can see my function c is a numerical Integral and my function e contains c as one of the building blocks. As vizaluisation here is the Code that plots my function e (just so you see that in theory a mean value should be existent):

``````(Tau)=4
d=0.5
w=5
Plot({e((Tau),g,d,w)},{g,0,5},AxesLabel->{Style("g",Bold,16)},PlotLabels->{Style("(Tau)(QSL)",Bold,13)})
``````

My Problem now is that I want to plot the Mean of function e over the interval and to do that I would need to calculate something along the Lines of

``````1/j*NIntegrate(e((Tau)_,g_,d_,w_),{g,0,j})
``````

and to plot this function

``````Plot({1/j*NIntegrate(e((Tau)_,g_,d_,w_),{g,0,j})},{j,0,5})
``````

which is the mean of e over g in (0,5).
But if I enter a code above in Mathematica it gives me a ton of errors. I guess this is due to the fact that mathematica has no explicit expression for the function I want to integrate because it in itself contains a numerical integration.

A double Integral does not work because my first integration of c is the denominator of the function e and I dont want to Integrate over 1/c by just putting

``````1/j*NIntegrate({a((Tau),g,d)*(Tau)/(Sqrt(-FractionBox("1", "8") (-1+SqrtBox(RowBox({"1", "-", SuperscriptBox("d", "2")}))) (2 SuperscriptBox("g", "2")+SuperscriptBox("w", "2")-SuperscriptBox("w", "2") Cos(2g*t))))},{{t,0,(Tau)}},{g,0,j})
``````