牛顿的2个方程方法

发布于 2025-02-13 20:41:43 字数 898 浏览 2 评论 0原文

我是一名初始程序员,目前正在将朱莉娅脚本转换为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱猫软卧 2025-02-20 20:41:43

如果问题仅仅是这里的语法:
顺便说一句,有很多未知的变量。

import math 
from scipy import optimize


def p(temp, irr):
    p_max = P_1 * math.exp(T_AP / T_P1 - T_AP / (temp + 273.15)) / (1 + math.exp(T_APL / (temp + 273.15) - T_APL / T_PL) + math.exp(T_APH / T_PH - T_APH / (temp + 273.15)))
    B_func = lambda x: p_max - (a * I_sat / math.log(1 + a / x)) * (a / (a + x)) * (x / (a + x))^(x / a)
    B = optimize.newton(B_func, 0)
    p_s = a * I_sat / math.log(1 + a / B)
    return p_s * (1 - math.exp(-a * irr / p_s)) * math.exp(-B * irr / p_s) 

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.

import math 
from scipy import optimize


def p(temp, irr):
    p_max = P_1 * math.exp(T_AP / T_P1 - T_AP / (temp + 273.15)) / (1 + math.exp(T_APL / (temp + 273.15) - T_APL / T_PL) + math.exp(T_APH / T_PH - T_APH / (temp + 273.15)))
    B_func = lambda x: p_max - (a * I_sat / math.log(1 + a / x)) * (a / (a + x)) * (x / (a + x))^(x / a)
    B = optimize.newton(B_func, 0)
    p_s = a * I_sat / math.log(1 + a / B)
    return p_s * (1 - math.exp(-a * irr / p_s)) * math.exp(-B * irr / p_s) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文