简体   繁体   English

如何绘制满足几个定积分的曲线?

[英]How can I draw a curve which satisfies several definite integrals?

Given data like the following: 给定如下数据: 条形图

I would like to draw a curve with the property that integrating over the intervals of the bars (eg 04:00 - 07:00) will give the same answer as that given by the bar chart (in this case, 62). 我想画一条曲线,其特性是在条形图的时间间隔(例如04:00-07:00)上积分将得到与条形图给出的相同答案(在本例中为62)。

I was planning to do this using numpy and scipy. 我打算使用numpy和scipy进行此操作。 I had a play with the interpolation library, but decided it wasn't what I was after. 我在插值库中玩过游戏,但是觉得那不是我想要的。

Does anyone know of a tool or algorithm for making such a curve? 有人知道制作这种曲线的工具或算法吗?

Let's figure out the linear system for computing the coefficients of a piecewise quadratic curve. 让我们找出用于计算分段二次曲线系数的线性系统。 Let there be n bars, where bar i (counting from 0 ) extends from x[i] to x[i+1] , with height y[i] . n条,其中条i (从0 )从x[i]延伸到x[i+1] ,高度为y[i] Piece i is the quadratic function 一块i是二次函数

lambda z: a[i]*z**2 + b[i]*z + c[i]

where a[i], b[i], c[i] are coefficients. 其中a[i], b[i], c[i]是系数。 We get n equations fixing the area. 我们得到固定面积的n方程。

a[i]*(x[i+1]**3 - x[i]**3)/3 + b[i]*(x[i+1]**2 - x[i]**2)/2 + c[i]*(x[i+1] - x[i])
    == y[i]*(x[i+1] - x[i]) for i in range(n)

We get n-1 equations matching up the values at boundaries. 我们得到n-1与边界值匹配的方程。

a[i]*x[i+1]**2 + b[i]*x[i+1] + c[i]
     == a[i+1]*x[i+1]**2 + b[i+1]*x[i+1] + c[i+1] for i in range(n-1)

We get n-1 equations matching up the derivatives at boundaries. 我们得到n-1与边界导数匹配的方程。

2*a[i]*x[i+1] + b[i] == 2*a[i+1]*x[i+1] + b[i+1] for i in range(n-1)

There are two more degrees of freedom. 还有两个自由度。 We could, eg, require that the beginning and ending derivatives be zero. 例如,我们可以要求开始和结束导数为零。

2*a[0]*x[0] + b[0] == 0
2*a[n-1]*x[n] + b[n-1] == 0

Use NumPy to solve these equations (this probably involves turning this system into a matrix). 使用NumPy求解这些方程式(这可能涉及将该系统转换为矩阵)。

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

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