Integration is related to the calculus of areas under curves, volumes, and several other applications
Integrals can be seen as antiderivatives, that is, the inverse operation for the derivative. Let's check this out on Maxima. Take the cases in the exercise done in the last tutorial:
Find out the derivatives and then the antiderivates: |
---|
Integrals on Maxima
integrate(2*x, x); 'integrate(2*x,x);
The first one returns the solution of the integral, and the second returns a symbolic representation of the integral
The definite integral is the area under the curve of a function, for a given interval. Let's see this for our well known function $f(x)=x^2$ in the interval from 0 to 1. In mathematical notation: $\int_0^1 f(x)~dx$
Let's try to solve this problem with the tools we have1). We don't know how to calculate the area under a curve, but we know how to calculate the area of a sequence of rectangles. Let's try to turn this curve into a series of rectangles!
Let's draw a graph of our problem:
############################## ## area under the curve f(x)= x^2; ## for the interval 0 - 1 ############################# par(mfrow=c(2,2)) seq.x=seq(0,1.5, by=0.1) seq.y=seq.x^2 plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= "Function x^2", xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) seq.x1=seq(0,1,by=0.1) seq.y1=seq.x1^2 polygon(c(1,0,seq.x1,1), c(0,0,seq.y1,0),col="red") title(sub=paste("Area= ??")) #savePlot("area_x2.jpeg", type="jpeg")
########################### #### Area approximation ### ########################### n.seq1=length(seq.x1) plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= "Minimum height",xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=seq.y1[-n.seq1],width=0.1, space=0, col="red", add=TRUE, yaxt="n") ############################## ## area of the rectangles ############################## h1=seq.y1[-n.seq1] (ar1= sum(h1*0.1)) title(sub=paste("Area=",ar1))
plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= "Maximum height", xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=seq.y1[-1],width=0.1, space=0, col="red", add=TRUE,, yaxt="n") lines(seq.x,seq.y) ################################# ## area of the rectangles ################################ h2=seq.y1[-1] (ar2= sum(h2*0.1)) title(sub=paste("Area=",ar2))
plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= "Average height", xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=diff(seq.y1)/2+seq.y1[-n.seq1],width=0.1, space=0, col="red", add=TRUE, yaxt="n") lines(seq.x,seq.y) ################################# ## area of the rectangles ################################ h3=diff(seq.y1)/2+seq.y1[-n.seq1] (ar3= sum(h3*0.1)) title(sub=paste("Area=",ar3)) ################################
Now let's decrease the size of the x intervals, starting from the code we wrote on the average height of the rectangle. This simulates a process in which the interval size goes to zero: $\Delta x \to 0$. We can formulate this as: $$\int_a^b f(x)~dx = \lim\limits_{\Delta x \to 0} \sum\limits_{i=1}^n f(x_i^*)\Delta x_i$$
#################################################### ## Decreasing the interval (base) of the rectangle## #################################################### x11() par(mfrow=c(2,2)) plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= "f(x)=x^2\t ; dx=0.1", xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=diff(seq.y1)/2+seq.y1[-n.seq1],width=0.1, space=0, col="red", add=TRUE, yaxt="n") lines(seq.x,seq.y) title(sub=paste("Area=",ar3))
############## ### dx=0.05 ## ############## dx=0.05 seq.05= seq(0,1, by=dx) seq.05y=seq.05^2 plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= paste("dx=", dx), xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=diff(seq.05y)/2+seq.05y[-length(seq.05y)],width=dx, space=0, col="red", add=TRUE, yaxt="n") lines(seq.x,seq.y) ################################# ## area of the rectangles ################################ h4=diff(seq.05y)/2+seq.05y[-length(seq.05y)] (ar4= sum(h4*dx)) title(sub=paste("Area=",ar4))
############## ### dx=0.01 ## ############## dx=0.01 seq.01= seq(0,1, by=dx) seq.01y=seq.01^2 plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= paste("dx=", dx), xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=diff(seq.01y)/2+seq.01y[-length(seq.01y)],width=dx, space=0, col="red", add=TRUE, yaxt="n") lines(seq.x,seq.y) ################################# ## area of the rectangles ################################ h5=diff(seq.01y)/2+seq.01y[-length(seq.01y)] (ar5= sum(h5*dx)) title(sub=paste("Area=",ar5))
############## ### dx=0.001 ## ############## dx=0.001 seq.001= seq(0,1, by=dx) seq.001y=seq.001^2 plot(seq.x,seq.y, type="l", bty="l", cex.lab=1.5, cex.axis=1.2, main= paste("dx=", dx), xlab="x", ylab="y") abline(v=0, lty=2) abline(h=0, lty=2) abline(v=1, lty=2) barplot(height=diff(seq.001y)/2+seq.001y[-length(seq.001y)],width=dx, space=0, col="red", add=TRUE, yaxt="n") lines(seq.x,seq.y) ################################# ## area of the rectangles ################################ h6=diff(seq.001y)/2+seq.001y[-length(seq.001y)] (ar6= sum(h6*dx)) title(sub=paste("Area=",ar6))
Now it's time to integrate some functions on Maxima. Open the file integral.wxm and apply the integral over the functions presented in the tutorial.