1
$\begingroup$

I have a function with the following form:

P0 = 1 / Sum[(lambda^i)/((mu^i)*i!), {i, 0, B1}] 
P = N[P0*lambda^B1/(mu^B1*B1!)] 

Where mu and lambda are fixed parameters and B1 is unknown.

The code refers to a Markov chain process that I am calculating.

enter image description here

And I need to find the minimum integer value of B1 that corresponds to the constraint P(B1) <= 0.05

Since I am new to the Mathematica, I find it a bit hard to use a correct function. Could you please point me to a correct way of solving such a problem with Mathematica?

Thank you.

UPD

@ulrich-neumann provided a better way to define the function:

F[mu_, lambda_] := (E^(-(lambda/mu)) lambda^B1 mu^-B1 Gamma[1 + B1])/(B1! Gamma[1 + B1, lambda/mu])

And @akku14 has built on top of the previous commentaries to define B1's boundaries:

NMinimize[{(F[1/3, 8] - .05)^2, F[1/3, 8] <= 0.05, B1 > 1, Element[B1, Integers]}, {B1, 5, 50}] to get {0.0000976008, {B1 -> 30}}

$\endgroup$
3
  • 2
    $\begingroup$ Ceiling[x /. FindRoot[f[x] == 0.05, {x, 100}]] $\endgroup$
    – Coolwater
    Aug 9, 2021 at 8:48
  • 1
    $\begingroup$ Please post the code about such function. $\endgroup$
    – cvgmt
    Aug 9, 2021 at 8:50
  • $\begingroup$ @cvgmt it is a simple Markov chain calculation, I want Pb not to exceed 0.05 and find a suitable B1 parameter P0 = 1 / Sum[(lambda^i)/((mu^i)*i!), {i, 0, B1}] P = N[P0*lambda^B1/(mu^B1*B1!)] $\endgroup$
    – Nik Ska
    Aug 9, 2021 at 10:52

1 Answer 1

1
$\begingroup$

First define your function depending on mu,lambda

F[mu_, lambda_] := (E^(-(lambda/mu)) lambda^B1 mu^-B1 Gamma[1 + B1])/(B1! Gamma[1 + B1, lambda/mu])    

Now it's possible to minimize for given parameters (examplary mu=1/3,lambda=8)

NMinimize[{B1, F[ 1/3, 8 ] <= 0.05, B1 > 0,Element[B1, Integers]}, B1 ]
(*{3., {B1 -> 3}}*)

This result seems to be wrong (Thanks @cvgmt`s comment)! Without the integer constraint NMinimize evaluates

NMinimize[{B1, F[ 1/3, 8 ] <= 0.05, B1 > 0 }, B1 ]
(* B1->29.172 *)

The correct solution follows to B1=30 !

$\endgroup$
12
  • $\begingroup$ Test the example F[1/3, 8] . The result should be 31 or 30 $\endgroup$
    – cvgmt
    Aug 9, 2021 at 12:38
  • $\begingroup$ @cvgmt Something wents wrong with the integerconstraint! Without my attempt gives B1->29.172 $\endgroup$ Aug 9, 2021 at 12:56
  • $\begingroup$ @UlrichNeumann thank you for the logic of solving. For some reasons I can't copy and paste your solution for a quick test, I get the following error: NMinimize :NMinimize was unable to generate any initial points satisfying the inequality constraints And {1.,{B1->1}} $\endgroup$
    – Nik Ska
    Aug 10, 2021 at 6:57
  • $\begingroup$ Try the last version (without integer constraint) NMinimize[{B1, F[ 1/3, 8 ] <= 0.05, B1 > 0,Element[B1, Integers]}, B1 ] (* B1->29.172 *) $\endgroup$ Aug 10, 2021 at 7:03
  • $\begingroup$ @UlrichNeumann I feel super dumb at this moment, but there is literally zero difference in formulas between the first and the second one. Should I also include comments? If so, it does not work as well. What am I missing here? Should I pre-define something else? $\endgroup$
    – Nik Ska
    Aug 10, 2021 at 8:36

Your Answer

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

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