# Exploring Integration

## Introduction

The process of finding integrals is called integration. Along with differentiation, integration is a fundamental operation of calculus, and serves as a tool to solve problems in mathematics and physics involving the area of an arbitrary shape, the length of a curve, and the volume of a solid, among others.
In this activity we will learn how to use MATLAB to compute antiderivatives (when it is possible) and the definite integrals using the command int().

## Before starting

Use the MATLAB Live Editor to edit and run this Live Script in your browser or your desktop.
2. Run the code within a section before starting to read the next.
3. To run the code from each section, click into the code section and then click on the Run Section button (from the toolstrip) or click on the blue stripe on left side of that section as shown below:
Remark: Run the code of each section from top to bottom, otherwise you may get an error.
- The end of a section is indicated with a thin line, like the next one -

## 1. Calculating antiderivatives

Recall that the indefinite integral is defined as
where is an antiderivative of , that is, ; and C is an arbitrary real constant.
Unfortunately, MATLAB does not calculate the indefinite integral, which is the set of all possible antiderivatives. However, it can calculate symbolically a particular antiderivative of a given function using the command
int(expr, var)
where expr is the function defined as a symbolic expression and var is a symbolic variable.
For example, consider the functions
, , and .
To calculate the antiderivative of each one of them, first we need to define them symbolically and then use the command int(). Thus, we have:
syms x y t a b % Define symbolic variables

fun1 = 3*x^2 - 2*x - 1 % Define f
antiDer1 = int(fun1) % Antiderivative of f

fun2 = sin(y) % Define g
antiDer2 = int(fun2) % Antiderivative of g

fun3 = cos(a*t + b) % Define h
antiDer3 = int(fun3, t) % Antiderivative of h. Here we specified the variable
Run this section to see the results. Also see what happens when you change the variable t to a or b in the last line of the code.
Recall also that integration is the inverse process to differentiation. Thus, if we wish to verify that the previous results are indeed antiderivatives of the functions and h, we just need differentiate them. This can be done with the command diff(). That is:
diff(antiDer1)
diff(antiDer2)
diff(antiDer3, t) % Here we need to specify the variable
You can also verify this in your notebook.

### 1.1 Interpreting results from MATLAB

MATLAB relies on well-known integration methods (substitution, integration by parts, partial fractions, etc.) and sophisticated algorithms for computing antiderivatives (when it is possible). However, you must carefully analyse the results provided by MATLAB to use them appropriately. For example, consider the function
.
You can easily verify that
is antiderivative of f. Now compare with the result provided by MATLAB:
syms x
f = 3*x^4-4*x^3+x;
antiDer = int(f)
Do you notice the differences? Are they the same antiderivatives? What do you think?

### 1. 2 Impossible indefinite integrals

Calculating indefinite integrals is a more complex process compared to calculating derivatives. In some cases, it is just an impossible task. We know this since 1830s thanks to French mathematician Joseph Liouville. For example, consider the function
.
If we use the command int() we get the output: .
MATLAB cannot calculate an expression or formula for this antiderivative. Not even the most powerful computer could do it.
syms x
int(x^x)
Other well-known examples of indefinite integrals that are impossible to calculate are
.
These are known as non-elementary integrals. However, some of them have been studied for many years by mathematicians and nowadays there exist numerical methods to define them, in particular for calculating definite integrals.

## 2. Calculating definite integrals

In order to find the value of the definite integral
we just need to add the interval of integration. That is
int(expr, var, a, b)
Let's see how this works with a few examples.

### Example 1:

Let's find the value of the integral
Thus, we write:
syms x
expr = sin(x)
int(expr,[0 pi])
Check this result is correct using the Fundamental Theorem of Calculus. That is, find an antiderivative and then use the formula
.

### Example 2:

Now let's evaluate the integral
.
One way to evaluate it is by using the method of substitution involving trigonometric identities. In MATLAB we just need to write:
syms x
expr = x^3/(4*x^2+9)^(3/2)
int(expr,[0 3*sqrt(3)/2])

## Remark!

Even though MATLAB can be very handy to compute antiderivatives and definite integrals, you still must
1. have a basic knowledge on how to calculate them using different methods of integration; and
2. analyse carefully the results provided by MATLAB.
Keep in mind that integration is more complicated task and there is no computer that can help you in all possible cases. In this case, humans are better than computers!

## 3. Hands on practice

Let's practice what we just learned.

### Activity 1:

Calculate the antiderivatives of the following functions:

Confirm your results by differentiating the obtained results (using the diff() function). Write your code here:

### Activity 2:

Calculate the following definite integrals
and
and analyse the results. Write your code here:

What do you notice? What can you say about the function ? Find an interval where you can calculate the definite integral.