【问题标题】:Calculate the area between two curves to the next intersection计算两条曲线到下一个交点的面积
【发布时间】:2020-09-02 10:02:04
【问题描述】:

我有两条相交多次的曲线。我不知道十字路口在哪里。我试图在不手动设置边界的情况下为两个交点之间的每个区域获取一个值。

到目前为止,我计算了每条曲线的值,如果 logifunc 高于 logifuncsoll,则用绿色绘制它们,如果 logifunc 低于 logifuncsoll,则用红色绘制。

E701077['logifuncsoll'] = 1811.7/ (1 + 769.67 * np.exp(-0.704566*(xsoll)))+14.5212
E701077['logifunc'] = 1847.28 / (1 + 312.09 * np.exp(-0.606454*(x701077)))-8.16471


plt.figure(dpi=300)
plt.plot(x701077, E701077['logifuncsoll'],'r',markersize=np.sqrt(1), label ="soll",color='red' )
plt.plot(x701077, E701077['logifunc'],'r',markersize=np.sqrt(1), label ="E701077",color='purple' )
plt.legend
fig, ax = plt.subplots(1, 1, sharex=True)
ax.plot(x701077, E701077['logifunc'],linewidth=1 , label='logifunc', color= 'purple')
ax.plot(x701077, E701077['logifuncsoll'],linewidth=1, label='logifuncsoll', color='black') 
ax.fill_between(x701077, E701077['logifuncsoll'], E701077['logifunc'], where=E701077['logifunc'] >= E701077['logifuncsoll'], facecolor='green', interpolate=True)
ax.fill_between(x701077, E701077['logifuncsoll'], E701077['logifunc'], where=E701077['logifunc'] <= E701077['logifuncsoll'], facecolor='red', interpolate=True)
ax.legend(loc='upper left', frameon=False)

【问题讨论】:

    标签: python pandas matplotlib integral


    【解决方案1】:

    两行总差是用scipy求差函数的绝对值积分。

    import scipy.integrate
    left_lim = 0
    right_lim = 27
    func = lambda x: abs( (1811.7/ (1 + 769.67 * np.exp(-0.704566*(x)))+14.5212)-
    (1847.28 / (1 + 312.09 * np.exp(-0.606454*(x)))-8.16471) )
    
    area = scipy.integrate.quad(func, left_lim, right_lim)
    

    要查找交点,请使用 Shapely。

    import shapely
    from shapely.geometry import LineString, Point
    
    line1 = LineString(E701077['logifuncsoll'].values)
    line2 = LineString(E701077['logifunc'].values)
    
    int_pt = line1.intersection(line2)
    point_of_intersection = int_pt.x, int_pt.y
    
    print(point_of_intersection)
    

    【讨论】:

    • 非常感谢!计算完美。但是有交叉点的部分给了我错误:ModuleNotFoundError: No module named 'shapely'我添加了你做的包。
    猜你喜欢
    • 2017-10-12
    • 2017-10-12
    • 2011-06-24
    • 2018-02-11
    • 1970-01-01
    相关资源
    最近更新 更多