0

I am trying to do a summation with repeated calculations in the "probability" variable, which cost a lot of time.

However, in each sum, the "probability" can be calculated from the last sum.I want to know if there is a way for sum to use the previous value? Or is there any advice on speeding up the Summation?

*Notes

  1. I have tried Assume plus FullSimplify on "probability",but it didn't simplify it.
  2. My final goal is to achieve n·value=400000,A·value=2000,L·value=6000.
(*Settings and Define distribution*)
ClearAll[n`value, A`value, L`value, r`value, mu, sigma, Fd, \
Ev`i`in`N, pauc`j, effi1, effi2, effi3, pro, n, L, x]

mu = 96228/10000; sigma = 2129/10000;

nvalue = 1000; Avalue = 200; L`value = 750;

Fd = LogNormalDistribution[mu, sigma];

(Basic Calculation) p = CDF[Fd, 3579899822703125/137438953472];

Eviin`N[n_, i_, v_] := Assuming[v > 0, NIntegrate[ v(n - 1)Binomial[n - 1, i - 1]* CDF[Fd, v]^(n - i)(1 - CDF[Fd, v])^(i - 1)PDF[Fd, v], {v, 0, 100000}, WorkingPrecision -> 50, AccuracyGoal -> 10, MinRecursion -> 5, MaxRecursion -> 10]];

probability[n_, j_] := Sum[Binomial[n, i]p^(n - i)(1 - p)^i*L`value/(n - i), {i, 1, j}];

(Target Sum) efficency = Sum[EviinN[nvalue, j, v]*probability[n`value, j - 1], {j, Avalue + 1, nvalue - L`value}] // AbsoluteTiming

My result is({31.5802, 664830.63374088788081035825330413985010418282188882})

Lomath
  • 119
  • 7
  • 3
    Are you looking for memorization? If so, see e.g. https://mathematica.stackexchange.com/a/25150/1871 I doubt if this is the bottleneck of the code, though. – xzczd Oct 26 '23 at 04:19
  • 1
    +1 to memoization. Memoizing both probability and Ev``i``in``N helps a bit. You can also Work with finite precision numbers instead of infinite precision. Each probability result is a very complicated expression, and applying N also helps a bit. – lericr Oct 26 '23 at 04:35

0 Answers0