3

For example, I have an expression as a (arbitrary) function of integer n

f[n_]:=10^n*(n^2+4*n)

I want to find the maximum integer n such that f[n]<=m for another number m.

I could formulate this as an integer programming/optimization problem. But that complicates things. I could also just try starting from 1 and continue to test whether the constraint is violated. Is there any more efficient or elegant way of doing this? Please note also the constraint may allow an Infinity value of n and I ideally want to detect this situation.

smci
  • 32,567
  • 20
  • 113
  • 146
Qiang Li
  • 10,593
  • 21
  • 77
  • 148

1 Answers1

5

Depends. If you can settle for a heuristic result using numeric methods, that makes the assumption an integer max is the floor of a real max, then can do as below.

f[n_] := 10^n*(n^2 + 4*n)

In[32]:= Floor[First[NMaximize[{n, f[n] <= 10^8}, n]]]
Out[32]= 6

Daniel Lichtblau

Daniel Lichtblau
  • 6,854
  • 1
  • 23
  • 30