trapezoids

505 days ago by mpaul

You can approximate the area under a curve by dividing the area up into really small trapezoids and finding the sum of their individual areas.

You can study that below.

Change dx to smaller and smaller values and see what happens.

Then see what happens when you change a and b.

Finally, you can also change f(x) to some other function.  For example, try f(x) = \sin(x).

f(x) = x^2 def trapezoid(b1, b2, h): return 1/2*(b1+b2)*h def trapezoids(f, a, b, dx): domain = [a..b, step = dx] return [trapezoid(f(x), f(x+dx), dx) for x in domain[:-1]] @interact def _(a=0, b=1, dx=1/5): domain = [a..b, step = dx] F = [(x,f(x)) for x in domain] show(plot(f, a, b) + points(F, color = 'red')+\ sum([line([(x,0),(x,f(x))]) for x in domain])+\ sum([line([P,Q], color = 'black') for (P, Q) in zip(F[:-1],F[1:])]), aspect_ratio = 1) print 'Sum of the areas of the trapezoids: ', sum(trapezoids(f, a, b, dx)).n() 
       
dx 

Click to the left again to hide and once more to show the dynamic interactive window

f(x) = x^2 f 
       
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ x^{2}
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ x^{2}
f.integral(x) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ \frac{1}{3} \, x^{3}
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ \frac{1}{3} \, x^{3}
f.integral(x,0,6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 72
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 72
f.integral(x,0,3) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 9
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 9
f.integral(x,0,6) - f.integral(x,0,3) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 63
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 63
f.integral(x, 3, 6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 63
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ 63