-2

Hello,
Can anyone help me,how to calculate the area between a curve(I have the data, not the equation) and a line(linear regression for this curve).I need to do the summation of the area below and under this line.

I tried but it is only for the continuous curve!:

from scipy import integrate

def f(x):
    return x**2

integrate.quad(f, x0, x1)

How can I calculate the desired area?

Arpit
  • 448
  • 8
  • 26
bak
  • 45
  • 1
  • 9
  • 1
    http://stackoverflow.com/a/13323861/6144626 – Ari Cooper-Davis May 13 '17 at 11:51
  • 1
    Interesting to note that simps in scipy.integrate can used points which are not evenly distributed. See the documentation [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html#scipy.integrate.simps) – Benedict Bunting May 13 '17 at 12:12

1 Answers1

1

I don't know is it is of much help, but if you only have the data for a set of points on the curve, you could look at using the Trapezium rule to generate a approximation of the are between the curve and the x-axis, provided you have a set of x and y values for points, using the SciPy library. You could then subtract the integral between the line and are. Like this:

import numpy as np
from scipy.integrate import simps
from scipy import integrate
#Our arrays of coordinates
xs = np.array([1,3,4])
ys = np.array([5,7,3])
I1 = simps(ys, xs)
#The line now
def f(x):
    #sum linear equation
    return 4x+5
I2 = integrate.quad(f, 1, 4)#use are x bounds from the outermost curve points
I = I1-I2

(Derived from information here)