c# - C# 中的 Lambert W 函数
问题描述
计算乘积对数函数的函数,也称为 Lambert W 函数。
通过使用它
double lam = LambertW(1);
解决方案
public static double LambertW(double x)
{
// LambertW is not defined in this section
if (x < -Math.Exp(-1))
throw new Exception("The LambertW-function is not defined for " + x + ".");
// computes the first branch for real values only
// amount of iterations (empirically found)
int amountOfIterations = Math.Max(4, (int)Math.Ceiling(Math.Log10(x) / 3));
// initial guess is based on 0 < ln(a) < 3
double w = 3 * Math.Log(x + 1) / 4;
// Halley's method via eqn (5.9) in Corless et al (1996)
for (int i = 0; i < amountOfIterations; i++)
w = w - (w * Math.Exp(w) - x) / (Math.Exp(w) * (w + 1) - (w + 2) * (w * Math.Exp(w) - x) / (2 * w + 2));
return w;
}
推荐阅读
- c# - 使用 ControlTemplate.Triggers 控制按钮前景色
- java - 无法使用 mmkv 存储库添加恢复的库
- python - 反向缩放中的 ValueError
- postgresql - 我的 Dockerized Flask Web 应用程序无法与本地 Postgres 连接
- javascript - 雪花:从另一个过程调用的带有 ARRAY 参数的过程
- python-3.x - 使用 Cartopy 绘制跨越日期线的 geoJSON 轨迹而不会出现错误线
- python - 当我 scan_dragto 平移我的画布时,所有画布项目都“正确移动”但它们的坐标不会改变
- apache-kafka - 在 Kafka MirrorMaker 2 上进行活动活动配置时避免主题上的集群前缀
- javascript - 如何在 html 文档中运行脚本并在节点中获取结果文档?
- java - 有没有办法在这段代码中使用一个while循环而不是2?