import matplotlib.pyplot as plt
import numpy as np
import math
def f(x):
    fun=(x**2-2*x)
    return fun
a=float(input("Enter the value of a="))  
b=float(input("Enter the value of b=")) 
h=float(input("Enter the value of h="))  
n=(b-a)/h
n=int(n)

sum=0.0
for i in range(1,n):
    x=a+i*h
    sum=sum+2*f(x)
inte=sum*(h/2.0)    
print("Integration is=",inte)

x=np.linspace(a,b,n)
plt.plot(x,f(x))
plt.xlabel("x")
plt.ylabel("y")
plt.title("Integration")
plt.legend(["x**2-2*x"])
plt.grid()
plt.show()

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: