2
$\begingroup$

Hope you are doing great!

I am trying to solve a double Integral of a function let's say f(w,q). My upper and lower limits are

wmin = 0;
wmax[T_] = T - 5;
qmin[w_, T_] := Sqrt[T] - Sqrt[(T - w)];
qmax[w_, T_] := Sqrt[T] + Sqrt[(T - w)];

The integral I am trying to solve is:

Iw[q_,T_] := NIntegrate[f[w,q], {w,wmin,wmax[T]}]

Iq[w_,T_] := NIntegrate[q*Iw[q,T], {q,qmin[w, T], qmax[w,T]}] /;(wmin<w<=wmax[T])

Iq[w_,T_] := 0 /; (w < wmin or w >= wmax[T])

The problem is that if I give the integral let's say a value of Iq[1,25], it will go and replace w to NIntegrate[f[1,q],d1] which will give an error. I want Mathematica to first solve the I1 NIntegral with respect to w for a given T(must be same for all integrals) and then calculate the second integral which only has w-dependence in the limits of qmin, qmax and the condition.

Thanks in advance!

$\endgroup$
1
  • $\begingroup$ Please provide your code (minimal working example) $\endgroup$ Commented Mar 7 at 8:54

1 Answer 1

1
$\begingroup$

Assuming

f = Function[{w, q}, 1];

we can integrate in one step as follows

int[ ww_?NumericQ, T_?NumericQ] := 
Boole[ (0 <= ww <= T - 5)] NIntegrate[q f[w , q], {q, Sqrt [T] - Sqrt[T - ww], Sqrt [T] + Sqrt[T - ww]} , {w, 0, T - 5}]

Plot3D[int[ww, T], {ww, 0, 10}  , {T, 0, 10},AxesLabel -> { ww, T, "int[ww,T]"} , MeshFunctions -> (#3 &), PlotPoints -> 50]

enter image description here

$\endgroup$
1
  • $\begingroup$ It worked thank you!! $\endgroup$ Commented Mar 8 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.