简体   繁体   English

曲线拟合指数

[英]Curve Fitting to Exponential

I am currently attempting to find the values of RH and TMP in the function for vapor pressure deficit (VPD) that result in the ideal VPD.我目前正在尝试在导致理想 VPD 的蒸汽压不足 (VPD) 函数中找到 RH 和 TMP 的值。 So I've defined my functions for VPD and tried to do a non-linear regression but am not getting the curve I am looking for.所以我已经为 VPD 定义了我的函数并尝试进行非线性回归,但没有得到我正在寻找的曲线。

import numpy as np
from scipy.optimize import curve_fit

def ES(C):
    es = 0.6108*np.exp((17.27*C)/(C+273.3))
    return es

def EA(RH,es):
    ea = (float(RH)/100)*es
    return ea

def VPD(C,RH):
    es = ES(C)
    ea = EA(RH,es)
    vpd = ea
    return vpd

C = np.linspace(0,50,100)
vpd = [0.5]*len(C)

popt, pcov = curve_fit(VPD, C, vpd)

Which gives me the values for popt and pcov of 10.09132776 and 0.51489686.这给了我 10.09132776 和 0.51489686 的 popt 和 pcov 值。 However, what I would really like to do here is determine the values of RH at these temperature values in C that give me VPD values of 0.5.但是,我真正想做的是确定这些温度值下的 RH 值(以 C 为单位),这使我的 VPD 值为 0.5。 I may be going about this in the wrong way but I've really been struggling with this for a long time and could really use some outside perspective as to how to go about this task.我可能会以错误的方式处理这个问题,但我真的已经为此苦苦挣扎了很长时间,并且真的可以使用一些外部观点来了解如何完成这项任务。

Assuming your equations are correct which I did not verify you can simply do this:假设你的方程是正确的,我没有验证你可以简单地这样做:

from sympy.solvers import solve
from sympy import Symbol

r = Symbol('r')
for C in np.linspace(0,50,100):
    result = solve(((r/100)*(0.6108*np.exp((17.27*C)/(C+273.3))))-0.5, r )
    print("For C = {} RH = {}".format(C, result[0]))

This will print the RH for each value of C assuming your equations are correct.假设您的方程是正确的,这将打印 C 的每个值的 RH。 I simply substituted the equations and set the resulting equation equal to 0. Just change the -0.5 to -(new VPD) to get the results for a different VPD.我只是简单地替换了方程并将结果方程设置为等于 0。只需将 -0.5 更改为 -(new VPD) 即可获得不同 VPD 的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM