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).
I was planning to do this using numpy and 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]
. Piece i
is the quadratic function
lambda z: a[i]*z**2 + b[i]*z + c[i]
where a[i], b[i], c[i]
are coefficients. We get n
equations fixing the area.
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.
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.
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).
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.