︠abbc19bf-031d-4d29-ab2f-080c7da19b1ei︠ %html
This notebook will help you with the following:
This notebook will help you with the following:
\nIf you enter a function, a range of $x$ values from $a$ to $b$, and a number $n$ of rectangles you want to create, the code below will compute both left and right endpoint approximations to the directed area under $f$. I said directed because if $a>b$, then you will get a negative, and if $f<0$ then you will get a negative as well.
︡d46806f9-7252-4175-b0f4-e76326810cad︡{"html": "If you enter a function, a range of $x$ values from $a$ to $b$, and a number $n$ of rectangles you want to create, the code below will compute both left and right endpoint approximations to the directed area under $f$. I said directed because if $a>b$, then you will get a negative, and if $f<0$ then you will get a negative as well.
"}︡ ︠3ce11ebe-a314-4f36-9ffd-f46c3dd7a76b︠ 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()] ]) ︡b88ab58d-5574-4a0b-98f8-d556d18e1226︡{"html": "\nx | \n0 | \n\\frac{1}{2} | \n1 | \n\\frac{3}{2} | \n2 | \n
y | \n4 | \n\\frac{15}{4} | \n3 | \n\\frac{7}{4} | \n0 | \n
dA = y dx | \n2 | \n\\frac{15}{8} | \n\\frac{3}{2} | \n\\frac{7}{8} | \n0 | \n
Left Sum | \n\\frac{25}{4} | \n6.25000000000000 | \n
Right Sum | \n\\frac{17}{4} | \n4.25000000000000 | \n
Average Sum | \n\\frac{21}{4} | \n5.25000000000000 | \n
Actual Area | \n\\frac{16}{3} | \n5.33333333333333 | \n
The following code will compute definite integrals, as well as graph a function and shade the region between the function and the $x$-axis.
You can type in your functions using $t$, $x$, or any other variable you wish.
︡e96a0b3d-bb5c-4ce9-99a2-4f87fa15d3e9︡{"html": "The following code will compute definite integrals, as well as graph a function and shade the region between the function and the $x$-axis.
\nYou can type in your functions using $t$, $x$, or any other variable you wish.
"}︡ ︠d9727ca0-1054-4f99-a5da-58ff6780e291︠ v(t)= 4-t^2 a=0 b=5 p=plot(v,a,b,fill=true).show() integrate(v,a,b) ︡5a8cebfb-d8aa-44bf-80c5-fe3f13e4ae83︡{"html": "If you want to find the area between $f$ and the $x$-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.
︡e0596da8-243e-4e50-9c96-0e2afc64f260︡{"html": "If you want to find the area between $f$ and the $x$-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.
"}︡ ︠5af96e10-4f68-4b0a-8be4-1ec1caa6ec9d︠ 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() ︡3b896fac-ba81-463b-8522-bb343ae96ff7︡{"html": "\nx intercepts | \n\\text{[\nx == 3,\nx == -2\n]} | \n
Integral of f | \n\\frac{1}{3} \\, x^{3} - \\frac{1}{2} \\, x^{2} - 6 \\, x | \n
Total Area | \n65.0 | \n
Positive Area | \n44.1666666667 | \n
Negative Area | \n20.8333333333 | \n
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 $AV$ is the $y$ value so that the area above $AV$ below $f$ is the same as the area below $AV$ and above $f$. 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.
︡207698dc-a51c-46d7-9915-29e5c0485929︡{"html": "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 $AV$ is the $y$ value so that the area above $AV$ below $f$ is the same as the area below $AV$ and above $f$. 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.
"}︡ ︠602360f5-21ed-4454-8b89-d8c854646573︠ 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."]]) ︡d9b4b0f7-ea6a-486a-8d9b-9ed62472b528︡{"html": "\nAverage Value | \n\\frac{8}{3} | \n
x values | \n\\text{[\nx == -2/3*sqrt(3),\nx == 2/3*sqrt(3)\n]} | \n
Notice how the area above the average value is the same as the area below. | \n