# Integration of functions when you have a formula
# for the function
def fun1(x):
return x**3
def fun2(x,p):
return np.sin(p*x)
import numpy as np
from scipy import integrate
# Integrate fun1 from 0 to 1 using the quad
# function. This uses a more sophisticated process
# than MATLAB's integral function.
# The result is returned as a tuple.
# s[0] = approximate value of integral
# s[1] = upper bound on error of approximation
s1 = integrate.quad(fun1,0,1)
print('s1 = ',s1)
# You can also handle integrals that have parameters
# lambda x: in Python
# has the same effect as
# @(x) in MATLAB
p = 4
s2 = integrate.quad(lambda x: fun2(x,p),0,1)
print('s2 = ',s2)