New course! Every coder should learn Generative AI!
Try a free lesson+ 3
Recently they've been teaching me Trapezoidal and Simpson's rule to calculate area under a graph.
And after searching I got that, numpy has a method called trapz for Trapezoidal rule and scipy.integrate has a method called simps for Simpson's rule. Try learning those methods in details to work with them.
0
could you share your code ?
I think that
"from scipy import integrate"
can help you
--=====================
Example :
from scipy import integrate
import numpy as np
import matplotlib.pyplot as plt
def f(x):
return x**2
x = np.array([-4,-3,-2,-1,0,1,2,3,4])
y = f(x)
plt.plot(x,y)
I = integrate.simps(y,x)
plt.savefig('foo.png')
print(I)