等分曲线下面积

sab*_*ath 1 algorithm math nonlinear-optimization

我有 ay = sin(x) 曲线,x 在 0 和 pi 之间(第一象限 - 无负值)。像这样的东西:

在此输入图像描述

我想将曲线下的面积平均划分为n块,并获取每块的(最大)x 值。

任何关于算法的想法将不胜感激。

Joh*_*anC 6

曲线下的面积是其积分。sin(x)0到 的积分u为,因此从到 的1-cos(u)积分为。对该公式求逆即可找到获得特定值的点。因此,我们正在寻找将其分成相等部分的值。0\xcf\x802tut=acos(1-u)u[0, 2]n

\n\n

在代码中:

\n\n
import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.linspace(-0.2, 3.3, 500)\ny = np.sin(x)\nplt.plot(x, y)\n\nn = 7\nu = np.linspace(0, 2, n + 1, endpoint=True)\nt = np.arccos(1 - u)\nprint("The limits of the areas are:", list(t))\n\ncolors = plt.cm.Set2.colors\nfor i in range(n):\n    filter = (x > t[i]) & (x <= t[i + 1])\n    plt.fill_between(x[filter], 0, y[filter], color=colors[i])\nplt.xticks(t)\nplt.gca().spines[\'bottom\'].set_position(\'zero\')\nplt.gca().spines[\'top\'].set_color(\'none\')\nplt.gca().spines[\'right\'].set_color(\'none\')\nplt.tight_layout()\nplt.show()\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果图

\n