Sololearn: Learn to Code
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.
27th Mar 2019, 8:55 AM
Шащи Ранжан
Шащи Ранжан - avatar
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)
27th Mar 2019, 8:46 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar