I have the following script:
import numpy as np
def f(x):
return x**2 + 3
def integration(a, b, n):
dx = (b - a) / n
integration = 0
for i in np.arange(1, n + 1):
integration += f(a + i * dx)
integration *= dx
return integration
print(integration (0, 5, 10000))
Now, I want to plot the curve of the f(x)
in the range described by a
and b
with integration area beneath it, so I can get something like this:
I know how to do the first part, ie plot the f(x)
curve in a specific range:
import matplotlib.pylab as pl
x = np.linspace(0, 5, 10000)
def f(x):
return x**2 + 3
pl.plot(x, f(x))
pl.xlim([-1, 6])
pl.show()
...but I lack the rest. I'll be grateful for help.