user3053081
user3053081

Reputation: 1

Numerical integration using SciPy on samples

I have a set of data points (x,y) where y=f(x). Samples are equally spaced with respect to x. I am trying to get SciPy to approximate the integral

formula

I had a go using this:

data = np.genfromtxt('data', delimiter=";")
y = data[:,1]  
x = data[:,0]
def f(x, y):
    return (x**2)*(np.exp(np.negative(1.6886*y)))
integral = integrate.simps(f, x)

The results I'm getting make no sense and there's probably some huuuge point I'm missing but would really appreciate any help.

Upvotes: 0

Views: 676

Answers (1)

kilico
kilico

Reputation: 23

integrate.simps is intended for evaluate an integral using samples, but no to evaluate by itself the function. I think you should use:

integral = integrate.simps(y, x)

e.g.

import scipy.integrate as inte
import numpy as np
x = np.linspace(0,2*np.pi, 100)
y = np.sin(x)**2
inte.simps(y,x)
>>> 3.1416352035913215

Upvotes: 1

Related Questions