# Solving a constrained convex optimization problem

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.

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}}

• Ceiling[x /. FindRoot[f[x] == 0.05, {x, 100}]] Commented Aug 9, 2021 at 8:48
• Please post the code about such function. Commented Aug 9, 2021 at 8:50
• @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!)] Commented Aug 9, 2021 at 10:52

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 @cvgmts 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 !

• Test the example F[1/3, 8] . The result should be 31 or 30 Commented Aug 9, 2021 at 12:38
• @cvgmt Something wents wrong with the integerconstraint! Without my attempt gives B1->29.172 Commented Aug 9, 2021 at 12:56
• @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}}  Commented Aug 10, 2021 at 6:57
• Try the last version (without integer constraint) NMinimize[{B1, F[ 1/3, 8 ] <= 0.05, B1 > 0,Element[B1, Integers]}, B1 ] (* B1->29.172 *)` Commented Aug 10, 2021 at 7:03
• @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? Commented Aug 10, 2021 at 8:36