0
$\begingroup$

I have a very simple trial that tries to get the value with a specific probability of not being exceeded, F, based on a Gaussian PDF

pdf = PDF[NormalDistribution[0, 1], r]

cdf[x_] := NIntegrate[pdf, {r, -Infinity, x}]

Solve[0.95 == cdf[x], x]

I get:

During evaluation of In[549]:= NIntegrate::inumr: The integrand pdf has evaluated to non-numerical values for all sampling points in the region with boundaries {{-\[Infinity],0. +x}}.

During evaluation of In[549]:= NIntegrate::inumr: The integrand pdf has evaluated to non-numerical values for all sampling points in the region with boundaries {{-\[Infinity],0. +x}}.

During evaluation of In[549]:= NIntegrate::inumr: The integrand pdf has evaluated to non-numerical values for all sampling points in the region with boundaries {{-\[Infinity],0. +x}}.

During evaluation of In[549]:= General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation.

During evaluation of In[549]:= Solve::inex: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help.

Out[549]= Solve[0.95 == NIntegrate[pdf, {r, -Infinity, x}], x]

whereas if I use:

Solve[0.95 == CDF[NormalDistribution[0, 1], x], x]

During evaluation of In[550]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[550]= {{x -> 1.64485}}

How to get a value out of Solve[0.95 == cdf[x], x]?

$\endgroup$
3
  • 2
    $\begingroup$ Try this ClearAll[ cdf ] ; cdf[ x_?NumericQ ] := NIntegrate[ pdf, {r, -Infinity, x} ] and then solve. $\endgroup$
    – LouisB
    Mar 2, 2020 at 20:25
  • $\begingroup$ Hi @LouisB, it gives me {{x ->cdf-1[0.95]}} $\endgroup$
    – jpcgandre
    Mar 2, 2020 at 21:21
  • 1
    $\begingroup$ Ok, I added Clear["Global*"]` and now it works... $\endgroup$
    – jpcgandre
    Mar 2, 2020 at 21:26

1 Answer 1

2
$\begingroup$

The problem is that in your version, Solve evaluates cdf symbolically. I add ?NumericQ to the definition to prevent this, and Solve now finds a solution (but warns that the solution might not be unique).

pdf = PDF[NormalDistribution[0, 1], r];
cdf[x_?NumericQ] := NIntegrate[pdf, {r, -Infinity, x}]
Solve[0.95 == cdf[x], x]

(* {{x -> 1.64485}} *)
$\endgroup$

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.