H.W.8

# rectangular_method HW8
import numpy as np
import matplotlib.pyplot as plt
def f(x):
return np.exp(x)
def integ_rect(f, x0, x1, N=1000):
s0=0.
h=(x1-x0)/N
x=x0
for i in range(0, N):
s0+=f(x+h/2.)*h
x+=h
return s0
if __name__=='__main__':
N=1000
sum=integ_rect(f, 0, 2.5, N)
print("integral exp(x) from x=0 to 2.5: ", sum, sep='')