在 Mathematica 中找到满足该代数约束的最大整数
例如,我有一个表达式作为整数 n
的(任意)函数,
f[n_]:=10^n*(n^2+4*n)
我想找到最大整数 n
使得 f[n]<= m
代表另一个数字m
。
我可以将其表述为整数规划/优化问题。但这让事情变得复杂了。我也可以尝试从 1 开始,继续测试是否违反约束。有没有更有效或更优雅的方法来做到这一点?另请注意,约束可能允许 n
的 Infinity
值,我理想情况下希望检测到这种情况。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
视情况而定。如果您可以使用数值方法获得启发式结果,即假设整数最大值是实际最大值的下限,则可以执行以下操作。
丹尼尔·利希布劳
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.
Daniel Lichtblau