在左侧和右手的两条曲线之间划分绿色区域

发布于 2025-01-29 21:59:15 字数 275 浏览 3 评论 0 原文

您好,如何计算绿色区域(以python为python)的值,该绿色区域的价值位于蓝线和蓝线右侧的其他区域?

因此,只有在黑线在黄线上的地方(线是由数组而不是函数产生的)

< img src =“ https://i.sstatic.net/fhbkk.png” alt =“显示Ilustrativ曲线”>

Hello how can i calculate the value of the green area (in python) which lies on the left from the blue line and on than the others on the right of the blue line?

so only where the black line is above the yellow line (the lines are resulting from an array not a function)

Shows an ilustrativ curve

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

雾里花 2025-02-05 21:59:15

如果您的黑线向量 f 和黄线 g 是在同一点定义的,则可以集成曲线 h = f -g 其中 h 大于零:

h = f - g
h_positive = h * (h>0)

”

如果您的 x 值存储在vector xx /code>,并且图块之间两个部分之间的截止是 cutoff (蓝线),然后您可以用 numpy> numpy.trapz

cutoff_idx = np.where(xx >= cutoff)[0][0]

left_area = np.trapz(h_positive[:cutoff_idx], xx[:cutoff_idx])
right_area = np.trapz(h_positive[cutoff_idx:], xx[cutoff_idx:])

print(f'Left area: {left_area}')
print(f'Right area: {right_area}')
print(f'Difference: {left_area - right_area}')

example Output(带有估计的输入数据):

Left area: 0.0034731843629035204
Right area: 0.021175629261965995
Difference: -0.017702444899062475

Provided your vectors of your black line f and your yellow line g are defined at the same points, you can integrate the curve h = f - g where h is greater than zero:

h = f - g
h_positive = h * (h>0)

Plot of h_positive with a vertical line showing a cutoff

If your x values are stored in a vector xx and your cutoff between the two parts of your plot is cutoff (the blue line) then you can calculate the integral of h_positive numerically with numpy.trapz:

cutoff_idx = np.where(xx >= cutoff)[0][0]

left_area = np.trapz(h_positive[:cutoff_idx], xx[:cutoff_idx])
right_area = np.trapz(h_positive[cutoff_idx:], xx[cutoff_idx:])

print(f'Left area: {left_area}')
print(f'Right area: {right_area}')
print(f'Difference: {left_area - right_area}')

Example output (with estimated input data):

Left area: 0.0034731843629035204
Right area: 0.021175629261965995
Difference: -0.017702444899062475
悸初 2025-02-05 21:59:15

让黑线为函数f(x),黄色为g(x)。您想做的是计算积分:

”在此处输入图像描述 其中a和b是f(x)和g(x)的相交点,其中g(x)&lt; f(x)。在您的示例中,您将必须计算3个这样的积分。

从算法上讲,您要做的是:

  1. 找到蓝线和X轴的交集,将X轴分为左右间隔。

  2. 对于每个间隔,请执行以下操作:

    2.1。查找f(x),g(x)

    的交点

    2.2。找到G(x)&lt的间隔; f(x)

    2.3。对于步骤2.2的每个间隔:

    2.3.1计算上述积分以找到绿色区域

每个 技能可以为您提供细节。

Let the black line be a function f(x) and yellow be g(x). What you want to do is calculate the integral:

enter image description here where a and b are intersection points of f(x) and g(x) at the interval where g(x) < f(x). In your example you will have to calculate 3 such integrals.

Algorithmically speaking what you have to do is:

  1. Find the intersection of the blue line and the x-axis to split to left and right interval.

  2. For each interval do the following:

    2.1. Find intersection points of f(x), g(x)

    2.2. Find the intervals for which g(x) < f(x)

    2.3. For each interval of step 2.2:

    2.3.1 Calculate the integral mentioned above to find the green area

I haven't worked with Python for Mathematical computations so I can't really guide you through the Python steps but hopefully my comment along with your googling skills can give you the specifics.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文