Actually, we have a similar broken curve. I want to find an approximating function, and calculate the area under it. I do not want a suggestive answer, it seems, see if there is math or scipy, but references to where there is a similar implementation, or at least. Similar, I am a beginner, and it is impossible to realize this on my own. 
- And why do you need to look for an approximating function? Take and stupidly calculate the values, in any case, it will be more accurate. - Xander
- oneHere is an example of how to calculate the integral for a function defined by a broken curve - jfs
|
1 answer
You can use numpy.trapz ()
Numpy example:
import numpy as np from scipy.integrate import simps from numpy import trapz x = np.linspace(0, 5, 21) y = np.pi / np.exp(x) # dx - ΡΠ°ΡΡΠΎΡΠ½ΠΈΠ΅ ΠΌΠ΅ΠΆΠ΄Ρ ΡΠΎΡΠ΅Π΄Π½ΠΈΠΌΠΈ X ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ°ΠΌΠΈ area = trapz(y, dx=5/20) Result:
In [19]: simps(y, dx=5/20) Out[19]: 3.1204919857832971 In [20]: trapz(y, dx=5/20) Out[20]: 3.1366600769000623 Schedule:
In [21]: plt.grid() In [22]: plt.plot(x, y) Out[22]: [<matplotlib.lines.Line2D at 0xd5a5c50>] In [23]: plt.grid() In [24]: plt.savefig('c:/temp/a.png') |
