here’s some sample Python code using the matplotlib library to plot the graph of y=sin(x) and the area under the curve between x=0 and x=pi/2:
pythonCopy codeimport numpy as np
import matplotlib.pyplot as plt
# Define the function to be integrated
def f(x):
return np.sin(x)
# Define the limits of integration
a, b = 0, np.pi/2
# Generate x and y values for plotting the function
x = np.linspace(0, np.pi, 100)
y = f(x)
# Create the plot
fig, ax = plt.subplots()
ax.plot(x, y, 'b', linewidth=2)
# Fill the area under the curve
ix = np.linspace(a, b)
iy = f(ix)
verts = [(a, 0), *zip(ix, iy), (b, 0)]
poly = plt.Polygon(verts, facecolor='0.9', edgecolor='0.5')
ax.add_patch(poly)
# Add labels and title
ax.text(0.75, 0.5, r"$\int_0^{\frac{\pi}{2}} \sin(x)dx = 1$", fontsize=14)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Integral of sin(x) from 0 to pi/2')
# Show the plot
plt.show()
This code generates the following graph:
