I have a function $F(z_h)$ given by,

$$F(z_h) = \int^{\infty}_{z_h} s(y) T'(y) dy$$

where $T \equiv T(z_h), T' \equiv T'(z_h), s \equiv s(z_h)$, which means they're all functions of $z_h$. Their expressions are all written in the code below. However, for the definition of $F$ I have to write $s$ and $T'$ in terms of a dummy variable to do an integration, where the lower limit is $z_h$. When I do this and evaluate, say $F(10)$, it gives me an error. I know this issue has something to do with the syntax and has seen this post (272204) but I'm not sure how to resolve it. Any guidance?

Note: In the code I have written T[m,zh], Tp[m,zh], F[m,zh] which is also a function of m, but this is just my convention, I could have declared the fixed value m write from the start, the one that changes is zh.

ag = 8;
pg = 8;
wp = 10;
a = 4.046;
b = 0.01613;
c = 0.227;
A[z_] := -a Log[b z^2 + 1]
Ap[z_] := D[A[z], z]
int1[zh_] := NIntegrate[y^3 Exp[-3 A[y]], {y, 0, zh}];
int2[zh_] := NIntegrate[y^3 Exp[-3 A[y] + c y^2], {y, 0, zh}];

s[zh_] := Exp[3 A[zh]]/(4 zh^3);
T[m_, zh_] := ((zh^3 Exp[-3 A[zh]])/(4 Pi int1[zh])) (1 - ((2 c m^2)/(1 - Exp[c zh^2])^2) (Exp[c zh^2] int1[zh] - int2[zh]));
Tp[m_, zh_] := (((3 zh^2 Exp[-3 A[zh]] - 3 Ap[zh] zh^3 Exp[-3 A[zh]]) int1[zh] - zh^6 Exp[-6 A[zh]])/(4 Pi int1[zh] int1[zh])) (1 - ((2 c m^2)/(1 - Exp[c zh^2])^2) (Exp[c zh^2] int1[zh] - int2[zh])) - 2 c m^2 ((zh^3 Exp[-3 A[zh]])/(4 Pi int1[zh])) (((2 c zh Exp[c zh^2] int1[zh]) (1 - Exp[c zh^2])^2 + 4 c zh Exp[c zh^2] (1 - Exp[c zh^2]) (Exp[c zh^2] int1[zh] - int2[zh]))/(1 - Exp[c zh^2])^4);
F[m_?NumericQ, zh_?NumericQ] := NIntegrate[s[y] Tp[m, y], {y, zh, Infinity}, AccuracyGoal -> 6, WorkingPrecision -> 10]

F[0.1, 10]

NIntegrate::nlim: y = y is not a valid limit of integration.
NIntegrate::nlim: y = y is not a valid limit of integration.
NIntegrate::nlim: y = y is not a valid limit of integration.
General::stop: Further output of NIntegrate::nlim will be suppressed during this calculation.
NIntegrate::inumr: The integrand (((-y^6 (1+Times[<<2>>])^24.276+(<<1>>+3 <<1>> <<1>>) <<1>>) (<<1>>))/(4 \[Pi] NIntegrate[y^3 Exp[<<1>>],<<1>>]^2)-(<<22>> <<2>> (<<1>>+<<1>>))/((<<1>>)^4 <<10>>[<<1>>]))/(4 y^3 (1+0.01613 y^2)^12.138) has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],10.00000000}}.
  • $\begingroup$ replace int1[zh_] by int1[zh_?NumericQ] (and same for int2). $\endgroup$ Commented May 11 at 15:20
  • $\begingroup$ @AccidentalFourierTransform It worked, but why only for int1 and int2? How about the other functions? $\endgroup$
    – mathemania
    Commented May 11 at 17:29


Your Answer

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

Browse other questions tagged or ask your own question.