简体   繁体   中英

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. 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.

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. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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