0
$\begingroup$

My code is:

p = 0.01; 
m = -0.5*Log[2.9]; 
s = Sqrt[Log[2.9]]; 
r = 0.5; 
tailF[x_] := 1 - CDF[NormalDistribution[0, 1], (Log[x] - m)/s] 
t = Quantile[LogNormalDistribution[m, s], p] 
g == 
  N[(Integrate[(tailF[y]/(1 - p))^(r), {y, t, Infinity}] - 
       Integrate[tailF[y]/(1 - p), {y, t, Infinity}]) / 
    (Integrate[ tailF[y]/(1 - p), {y, t, Infinity}])] 
v1 == 
  -r ΝIntegrate[((tailF[x]/(1 - p))^r) Log[tailF[x]/(1 - p)], {x, t, Infinity}]

NIntegrate::inumri: The integrand 1.00504 (1-1/2 Erfc[-0.484567 (0.532355 +Log[<<1>>])])^0.5 Log[1.0101 (1-1/2 Erfc[-0.484567 Plus[<<2>>]])] has evaluated to Overflow, Indeterminate, or Infinity for all sampling points in the region with boundaries {{0.0532481,5.23043*10^7}}

General::stop: Further output of NIntegrate::inumri will be suppressed during this calculation.

Can you please help why I am getting this message?

$\endgroup$
  • $\begingroup$ NIntegrate::inumri: The integrand 1.00504 (1-1/2 Erfc[-0.484567 (0.532355 +Log[<<1>>])])^0.5 Log[1.0101 (1-1/2 Erfc[-0.484567 Plus[<<2>>]])] has evaluated to Overflow, Indeterminate, or Infinity for all sampling points in the region with boundaries {{0.0532481,5.23043*10^7}}. $\endgroup$ – Polixeni Vliora Jan 18 at 20:35
  • 4
    $\begingroup$ Please provide the code that generates the message. $\endgroup$ – Anton Antonov Jan 18 at 20:40
  • $\begingroup$ v1 == -0.5 ΝIntegrate[ 1.00504 (1 - 1/2 Erfc[-0.685282 (0.532355 + Log[x])])^0.5 Log[ 1.0101 (1 - 1/2 Erfc[-0.685282 (0.532355 + Log[x])])], {x, 0.0532481, [Infinity]}] my question is how i can computing this result $\endgroup$ – Polixeni Vliora Jan 18 at 22:09
  • $\begingroup$ Because more than 3 messages of the form NIntegrate::inumri were thrown. That means you are doing something wrong quite often. I guess something bad is going on with your integrand. $\endgroup$ – Henrik Schumacher Jan 18 at 22:10
  • $\begingroup$ you have right!! thank you! $\endgroup$ – Polixeni Vliora Jan 18 at 22:12
3
$\begingroup$

Edit

Your numeric problems are induced because you are using machine precision arithmetic. The fix is to define the parameters as exact quantities and do the computations with Mathematica's arbitrary precision arithmetic.

You also have some bad syntax in your code, I will correct those errors in presentation of the making of the computation with arbitrary precision arithmetic.

My solution uses exactly the same approach as Bob Hanlon's, but I also worked out a computation for g. I omit repeating Bob's work, but give the code for computing g.

p = 1/100;
q = 29/10;
m = -Log[q]/2;
s = Sqrt[Log[q]];
r = 1/2;

tailF[x_] := 1 - CDF[NormalDistribution[0, 1], (Log[x] - m)/s]

t = N[Quantile[LogNormalDistribution[m, s], p], 20]

0.053248094037394870890`

g =
  Module[{int1, int2},
    int1 = NIntegrate[tailF[y]/(1 - p), {y, t, ∞}, WorkingPrecision -> 20];
    int2 = NIntegrate[(tailF[y]/(1 - p))^(r), {y, t, ∞}, WorkingPrecision -> 20];
    (int2 - int1)/int1]

2.0043916495150882408

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you so much!! I have a very short time learning this program. In the future I will have more questions!!! :) You where very helpful!! $\endgroup$ – Polixeni Vliora Jan 18 at 23:37
  • $\begingroup$ v == Module[{int3, int4}, int3 = -r* NIntegrate[((tailF[y]/(1 - p))^r)*Log[tailF[y]/(1 - p)], {y, t, Infinity}, WorkingPrecision -> 20]; int4 = NIntegrate[(tailF[y]/(1 - p))^r, {y, t, Infinity}, WorkingPrecision -> 20]; int3/int4]... i bult this one with the some thought but it give False for p=0! $\endgroup$ – Polixeni Vliora Jan 19 at 0:00
  • $\begingroup$ @BobHanlon. I have corrected the error. $\endgroup$ – m_goldberg Jan 19 at 0:14
  • $\begingroup$ @PolixeniVliora. Why are you using == rather than =? With p =0. the righthand side gives 1.8913582973597114875. Why do expect testing for equality to v, which is what you are doing, would give True, the only other value your expression could have. $\endgroup$ – m_goldberg Jan 19 at 0:22
  • $\begingroup$ yes i found it after i sent the message. Can i ask you something else..? When i get another distribution its happened numerical problem and the program doesnt compute the intervals.. $\endgroup$ – Polixeni Vliora Jan 19 at 1:10
2
$\begingroup$

Use exact constants so that the numerical integration can be done with a specified level of precision.

p = 1/100; 
m = -1/2*Log[29/10]; 
s = Sqrt[Log[29/10]]; 
r = 1/2;

tailF[x_] := 1 - CDF[NormalDistribution[0, 1], (Log[x] - m)/s] 

t = Quantile[LogNormalDistribution[m, s], p];

v1 = -r*NIntegrate[((tailF[x]/(1 - p))^r)*Log[tailF[x]/(1 - p)], 
    {x, t, Infinity}, WorkingPrecision -> 20]

(* 5.4205112147940705531 *)

EDIT: regarding the comment,

a = NIntegrate[(tailF[x]/(1 - p))^r, {x, t, Infinity}, WorkingPrecision -> 20]

(* 2.8735704898654341928 *)

v1/a

(* 1.8863331294329607670 *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ so you suggest me to calculate a finite number, ok thank you. But if i want this one v1 = -r*NIntegrate[((tailF[x]/(1 - p))^r)*Log[tailF[x]/(1 - p)], {x, t, Infinity}]/(Integrate[(tailF[x]/(1 - p))^r, {x, t, Infinity}), WorkingPrecision -> 20]??? i'm grateful for helping me!! $\endgroup$ – Polixeni Vliora Jan 18 at 22:44

Your Answer

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

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