Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168717
Image: ubuntu2004

Definite Integrals

This notebook will help you with the following:

  • Estimating area under curves using left and right endpoint approximations.
  • Finding area under postive curves using definite integrals, as well as finding diplacement from velocity.
  • Finding area between functions and the x axis.
  • Finding average value.
#auto var('x,y,t')
(x, y, t)

Approximating Area

If you enter a function, a range of xx values from aa to bb, and a number nn of rectangles you want to create, the code below will compute both left and right endpoint approximations to the directed area under ff.  I said directed because if a>ba>b, then you will get a negative, and if f<0f<0 then you will get a negative as well.

f(x)=4-x^2 a=0 b=2 n=4 dx=(b-a)/n xvalues=[(a+k*dx) for k in range(0,n+1)] yvalues=[f(c) for c in xvalues] dAvalues=[f(c)*dx for c in xvalues] p=plot(f,a,b) for k in range(0,n+1): p+=point((xvalues[k],yvalues[k]),rgbcolor='black') p+=line([(xvalues[k],0),(xvalues[k],yvalues[k])],rgbcolor='black') for k in range(1,n+1): p+=polygon([(xvalues[k]-dx,0),(xvalues[k]-dx,yvalues[k]),(xvalues[k],yvalues[k]),(xvalues[k],0)],rgbcolor=(1,0,0),alpha=.2) p+=polygon([(xvalues[k-1]+dx,0),(xvalues[k-1]+dx,yvalues[k-1]),(xvalues[k-1],yvalues[k-1]),(xvalues[k-1],0)],rgbcolor=(0,0,1),alpha=.2) leftsum=sum([dAvalues[k] for k in range(0,n)]) rightsum=sum([dAvalues[k] for k in range(1,n+1)]) xvalues.insert(0,"x") yvalues.insert(0,"y") dAvalues.insert(0,"dA = y dx") html.table([ xvalues,yvalues,dAvalues ]) p.show() html.table([ ["Left Sum",leftsum,leftsum.n()], ["Right Sum",rightsum,rightsum.n()], ["Average Sum",(leftsum+rightsum)/2,((leftsum+rightsum)/2).n()], ["Actual Area",integrate(f,a,b),integrate(f,a,b).n()] ])
x 0 \frac{1}{2} 1 \frac{3}{2} 2
y 4 \frac{15}{4} 3 \frac{7}{4} 0
dA = y dx 2 \frac{15}{8} \frac{3}{2} \frac{7}{8} 0
Left Sum \frac{25}{4} 6.25000000000000
Right Sum \frac{17}{4} 4.25000000000000
Average Sum \frac{21}{4} 5.25000000000000
Actual Area \frac{16}{3} 5.33333333333333

Definite Integrals abf(x)dx\displaystyle \int_a^b f(x) dx

The following code will compute definite integrals, as well as graph a function and shade the region between the function and the xx-axis.

  • If you type in velocity, it will find the change in position.
  •  If you type in a positive function, it will compute the area under the graph.

You can type in your functions using tt, xx, or any other variable you wish.

v(t)= 4-t^2 a=0 b=5 p=plot(v,a,b,fill=true).show() integrate(v,a,b)
-65/3

Area between ff and the xx-axis.

If you want to find the area between ff and the xx-axis, the first step is to find the zeros of the function. Then you break the integral to integrate over positive and negative parts separately.  The code below will find the zeros, give you the integral, tell you the area from both the positive and negative parts, as well as the total area.

f(x) = x^2-x-6 a=-5 b=5 x_intercepts = solve(f,x) p=plot(f,a,b,fill=true) DI=integrate(abs(f(x)),a,b) g=abs(f) Area=g.nintegrate(x,a,b) PA=((g+f)/2).nintegrate(x,a,b) NA=((g-f)/2).nintegrate(x,a,b) html.table([ ["x intercepts", x_intercepts], ["Integral of f", integrate(f(x),x)], ["Total Area", Area[0]], ["Positive Area", PA[0]], ["Negative Area", NA[0]], ]) p.show()
x intercepts \text{[ x == 3, x == -2 ]}
Integral of f \frac{1}{3} \, x^{3} - \frac{1}{2} \, x^{2} - 6 \, x
Total Area 65.0
Positive Area 44.1666666667
Negative Area 20.8333333333

Average Value 1baabf(x) dx\displaystyle \frac{1}{b-a}\int_a^b f(x)\ dx

The code below computes the average value of a function. Remember that the average value of a continuous function always passes through the function.  The average value AVAV is the yy value so that the area above AVAV below ff is the same as the area below AVAV and above ff. I like to think of average value as the height of sand in an ant farm that would result from shaking the ant farm to make a level top.

f(x) = 4-x^2 a=0 b=2 average_value = 1/(b-a)*integrate(f,a,b) sols=solve(f(x)==average_value,x) html.table([ ["Average Value", average_value], ["x values", sols], ]) p=plot(f,a,b,fill=true,fillalpha=.2,fillcolor='red') p+=plot(average_value,a,b,fill=true,fillalpha=.2,fillcolor='blue',color='black') p.show() html.table([["Notice how the area above the average value is the same as the area below."]])
Average Value \frac{8}{3}
x values \text{[ x == -2/3*sqrt(3), x == 2/3*sqrt(3) ]}
Notice how the area above the average value is the same as the area below.