0
$\begingroup$

This calculation takes a very long time!

  1. Why?
  2. How can I improve it?

Thanks!

n[μ_] := Integrate[1/(0.3 Sqrt[2 π]) E^(-(1/2) ((x - μ)/0.3)^2), {x, -∞, 501.13}]

Solve[n[μ] == 0.05]
$\endgroup$
  • $\begingroup$ try replacing .3 and 501.13 with Rationalize[0.3] and Rationalize[ 501.13] $\endgroup$ – kglr Oct 9 '18 at 21:24
  • $\begingroup$ Works quite fast:Solve[Integrate[5/3 E^(-(50/9) (x - μ)^2) Sqrt[2/π], {x, -∞, 50113/100}] == 5/100, μ][[1]] // AbsoluteTiming (* {2.81637, {μ -> 1/100 (50113 + 30 Sqrt[2] InverseErfc[1/10])}*) $\endgroup$ – Mariusz Iwaniuk Oct 9 '18 at 21:38
  • $\begingroup$ Pretty sure this is a dupe... $\endgroup$ – J. M. will be back soon Oct 10 '18 at 2:14
  • $\begingroup$ @kglr Interesting! Why does Rationalize work? $\endgroup$ – GambitSquared Oct 10 '18 at 5:44
5
$\begingroup$
dist = NormalDistribution[μ, 3/10];

The integral is

n[μ_] = Integrate[PDF[dist, x], {x, -∞, 50113/100}]

(* 1/2 Erfc[(-50113 + 100 μ)/(30 Sqrt[2])] *)

Alternatively, it is just the CDF

n2[μ_] = CDF[dist, 50113/100]

(* 1/2 Erfc[5/3 Sqrt[2] (-(50113/100) + μ)] *)

Verifying that they are equivalent expressions,

n[μ] == n2[μ] // Simplify

(* True *)

The exact solution is

sol = Solve[n[μ] == 1/20, μ][[1]] // Quiet

(* {μ -> 1/100 (50113 + 30 Sqrt[2] InverseErfc[1/10])} *)

Verifying the solution,

n[μ] /. sol

(* 1/20 *)

The numeric value is

sol // N

(* {μ -> 501.623} *)
$\endgroup$
  • $\begingroup$ Instead of using Solve[] here, it is better to use the intended functions Quantile[] or InverseCDF[]. $\endgroup$ – J. M. will be back soon Oct 10 '18 at 2:13
  • $\begingroup$ @J.M.issomewhatokay. - seems like Solve or Reduce would still be needed, e.g., Solve[Quantile[dist, 1/20] == 50113/100, μ][[1]] or Solve[InverseCDF[dist, 1/20] == 50113/100, μ][[1]] $\endgroup$ – Bob Hanlon Oct 10 '18 at 2:43
4
$\begingroup$

We have the identity

CDF[NormalDistribution[μ, σ], x] == CDF[NormalDistribution[], (x - μ)/σ] // Simplify
   True

which means

With[{σ = 3/10, p = 1/20, x = 50113/100},
         x - σ Quantile[NormalDistribution[], p]] // N

is the solution to the problem posed in the OP.

$\endgroup$
  • $\begingroup$ (I only have a smartphone and gedanken Mathematica right now, so please edit my answer if the formatting looks off.) $\endgroup$ – J. M. will be back soon Oct 10 '18 at 3:51
  • $\begingroup$ "I only have a smartphone and gedanken Mathematica right now"...Now that's what I call confidence and a good memory. (And no surprise, it checks out.) $\endgroup$ – JimB Oct 10 '18 at 5:59
  • $\begingroup$ It ain't a great situation, but I'm making the most of what I have. :) $\endgroup$ – J. M. will be back soon Oct 10 '18 at 6: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.