Tutorials

Population
Structure
Dynamics
Density-independent
Density-dependent
Strutured Population
Metapopulation
Single Species
Two Species
Community
Estrutura
Dynamics and Disturbances
Dinâmicas Neutras

Mathematics & Statistics
Differential and Integral Calculus
Stochastic Processes

Visitors

en:ecovirt:roteiro:math:integralr

Integration

Integration is related to the calculus of areas under curves, volumes, and several other applications

Indefinite integrals

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:
1. $f(x) = exp(x) + x^7$
2. $f(x) = x + sin(x)$
3. $f(x) = 5x^3 + 2$
4. $f(x) = cos(x) + sin(x)$
5. $f(x) = x^2 + x^3cos(x)$
6. $f(x) = exp(x) ln(x)$
7. $f(x) = x^5sin(x)$
8. $f(x) = \frac{1}{x}$
9. $f(x) = \frac{1}{x^2}$
10. $f(x) = \frac{exp(x)}{x}$
11. $f(x) = \frac{sin(x)}{x^2}$

Integrals on Maxima

The function for integration on Maxima is the integrate, which has for arguments the function and the variable over which to integrate. There are two forms to use this function:
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

Definite integrals

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$

Approximate area

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")

Calculating the area

###########################
#### 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)

##############################
## area of the rectangles
##############################
h1=seq.y1[-n.seq1]
(ar1= sum(h1*0.1))
title(sub=paste("Area=",ar1))

Another solution

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)
lines(seq.x,seq.y)
#################################
## area of the rectangles
################################
h2=seq.y1[-1]
(ar2= sum(h2*0.1))
title(sub=paste("Area=",ar2))

Average height


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)
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))
################################

Smaller intervals

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$$

$d_x=0.1$

####################################################
## 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)
lines(seq.x,seq.y)
title(sub=paste("Area=",ar3))

$d_x=0.05$

##############
### 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)
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))

$d_x=0.01$

##############
### 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)
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))

$d_x=0.001$

##############
### 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)
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))

Maxima

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.

1)
but beware of the Maslow Hammer: “if all you have is a hammer, everything looks like a nail”