牛顿的2个方程方法
我是一名初始程序员,目前正在将朱莉娅脚本转换为Python。它涉及以下朱莉娅代码:
function p(temp, irr)
p_max = P_1 *
exp(T_AP / T_P1 - T_AP / (temp + 273.15)) /
(1 + exp(T_APL / (temp + 273.15) - T_APL / T_PL) + exp(T_APH / T_PH - T_APH / (temp + 273.15)))
β_func(x) = p_max -
(α * I_sat / log(1 + α / x)) * (α / (α + x)) * (x / (α + x))^(x / α)
β = find_zero(β_func, (0, 0.1), Bisection())
p_s = α * I_sat / log(1 + α / β)
return p_s * (1 - exp(-α * irr / p_s)) * exp(-β * irr / p_s)
end
据我了解,该代码找到一个x值,x值P_MAX和β_FUNC之间的差异为零,并且在P_S方程中使用此值。
我一直在尝试将此代码转换为Python一段时间,而没有任何成功。在Python中使用牛顿方法有几个示例(例如, https://personal.math.ubc.ca/~pwalls/math-python/roots-optimization/newton/newton/ ),但是这些示例使用1个方程而不是2
。欢迎。谢谢!
I'm a beginning programmer who's currently working on translating a Julia script to Python. It concerns the following piece of Julia code:
function p(temp, irr)
p_max = P_1 *
exp(T_AP / T_P1 - T_AP / (temp + 273.15)) /
(1 + exp(T_APL / (temp + 273.15) - T_APL / T_PL) + exp(T_APH / T_PH - T_APH / (temp + 273.15)))
β_func(x) = p_max -
(α * I_sat / log(1 + α / x)) * (α / (α + x)) * (x / (α + x))^(x / α)
β = find_zero(β_func, (0, 0.1), Bisection())
p_s = α * I_sat / log(1 + α / β)
return p_s * (1 - exp(-α * irr / p_s)) * exp(-β * irr / p_s)
end
As far as I understand, the code finds an x value for which the difference between p_max and β_func is zero, and uses this value in the equation for p_s.
I've been trying to translate this code to Python for a while now, without any success. There are several examples of applying Newton's method in Python (e.g., https://personal.math.ubc.ca/~pwalls/math-python/roots-optimization/newton/), but these examples use 1 equation instead of 2.
Any help or insights are very welcome. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果问题仅仅是这里的语法:
顺便说一句,有很多未知的变量。
If the problem is simply the syntax here you are : (I imported a scipy function, so you have to install scipy module to run this)
And btw there's a lot of unknown variables.